Skip to content

Commit 5a2943a

Browse files
add additional type information and remove redis and psql (dydxinterviews#2)
1 parent 075dc7d commit 5a2943a

12 files changed

+3259
-5223
lines changed

Diff for: Dockerfile

-20
This file was deleted.

Diff for: README.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<p align='center'><img src='https://dydx.exchange/logo.svg' width='256' /></p>
22

33
The goal of this repository is to verify that your development environment is set up to start working on code at dYdX. Successfully running the tests in this repo confirms that your environment is close to or completely set up to work with dYdX repositories.
4+
We also provide examples of common Typescript types you will encounter at dYdX in `src/types`. These objects are then used and tested in `__tests__/basicFlowTests`.
45

56
## Git
67
Clone the repository with one of the following
@@ -47,16 +48,11 @@ Set your node version to 12. NVM is a good tool for managing your node version.
4748

4849
```nvm use 12```
4950

50-
## Docker
51-
52-
We use docker locally to support running tests against a realistic environment, with (e.g.) postgres and redis running in dockerized containers. You’ll need to [download](https://www.docker.com/get-started) and start docker locally, as well as install [docker-compose](https://docs.docker.com/compose/install).
53-
5451
## Running Tests
5552

5653
* Run all commands from the root directory of the repository.
5754
* In one terminal run `npm run compile:watch`. This will allow for continual building as you make changes to files.
58-
* In a second terminal run `docker-compose up`. This will bring up an instance of redis, postgres and kafka locally to be used in tests.
59-
* In a third terminal run your tests with `npm run test`. You can add a test filename as an optional argument if you don’t want to run the whole test suite. This command pattern matches for all files with .test.ts so you don’t need to include the entire path, for example `npm test -- __tests__/basicFlowTests`.
55+
* In a second terminal run your tests with `npm run test`. You can add a test filename as an optional argument if you don’t want to run the whole test suite. This command pattern matches for all files with .test.ts so you don’t need to include the entire path, for example `npm test -- __tests__/basicFlowTests`.
6056

6157
## Additional Links
6258

Diff for: __tests__/basicFlowTests.test.ts

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
import { knexPrimary } from '../src/db/knexfile';
2-
import { createRedisClient, getAsync, setAsync } from '../src/db/redis';
3-
4-
const res = createRedisClient('redis://localhost:6382', 500);
5-
6-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7-
export const redis: any = res?.client;
8-
export const connect = res?.connect;
1+
import { Market, MarketInformation } from '../src/types';
92

103
describe('tests', () => {
11-
it('test postgres connection', async () => {
12-
const queryDB = await knexPrimary.raw('select * from pg_indexes');
13-
expect(queryDB).not.toEqual(null);
14-
});
4+
it('basic test', async () => {
5+
const btcInformation: MarketInformation = {
6+
market: Market.BTC_USD,
7+
creationDate: ' 2021-12-17T23:00:00.000Z',
8+
exchangePrices: {
9+
coinbase: {
10+
lastPrice: 49000,
11+
marketId: '1',
12+
},
13+
ftx: {
14+
lastPrice: 49800,
15+
marketId: '2',
16+
},
17+
},
18+
};
1519

16-
it('test redis', async () => {
17-
await setAsync({
18-
key: 'key',
19-
value: 'value',
20-
}, redis);
20+
expect(btcInformation.market).toEqual(Market.BTC_USD);
21+
expect(btcInformation.exchangePrices.coinbase.lastPrice).toEqual(49000);
2122

22-
const val: string | null = await getAsync('key', redis);
23-
expect(val).toEqual('value');
23+
// iterating over the keys of the exchangePrices
24+
Object.keys(btcInformation.exchangePrices).forEach((exchange: string) => {
25+
expect([
26+
'coinbase',
27+
'ftx',
28+
].includes(exchange));
29+
});
2430
});
2531
});

Diff for: docker-compose.yml

-31
This file was deleted.

Diff for: jest.config.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
// Use the base configuration as-is.
2-
module.exports = require('./node_modules/@dydxprotocol/node-service-base-dev/jest.config.js');
1+
module.exports = {
2+
roots: [
3+
'<rootDir>/__tests__',
4+
],
5+
transform: {
6+
'^.+\\.ts$': 'ts-jest',
7+
},
8+
testRegex: '__tests__\\/.*\\.test\\.ts$',
9+
moduleFileExtensions: [
10+
'ts',
11+
'js',
12+
'json',
13+
'node',
14+
],
15+
globalSetup: './jest.globalSetup.js',
16+
resetMocks: true,
17+
setupFilesAfterEnv: ['./jest.setup.js'],
18+
testEnvironment: 'node',
19+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/helpers/'],
20+
testTimeout: 5000,
21+
};

Diff for: jest.globalSetup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This function runs once before all tests.
22
module.exports = () => {
3-
// eslint-disable-next-line
4-
require('dotenv-flow').config();
3+
// eslint-disable-next-line global-require
4+
require('dotenv-flow/config');
55
};

0 commit comments

Comments
 (0)