-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(models): add master-pair.repository spec
- Loading branch information
1 parent
9dc1141
commit 205a2a6
Showing
12 changed files
with
127 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
modules/models/entity/master-pair/master-pair.repository.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { EntityTestBed, MasterPairEntity, MasterPairEntityCreateParams, MasterPairRepository } from '@dripjs/models'; | ||
import { getPairDefaultData } from '@dripjs/testing'; | ||
|
||
describe('master-pair.repository', () => { | ||
let masterPairReposity: MasterPairRepository; | ||
const defaultData = getPairDefaultData(); | ||
const pair = 'xbtusd'; | ||
|
||
beforeAll(async () => { | ||
await EntityTestBed.setup(); | ||
masterPairReposity = EntityTestBed.getRepository(MasterPairRepository); | ||
}); | ||
|
||
afterAll(async () => { | ||
await EntityTestBed.cleanup(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await EntityTestBed.reset(); | ||
await masterPairReposity.insertNewPairs(defaultData); | ||
}); | ||
|
||
describe('insertNewPair', () => { | ||
it('should insert new pair', async () => { | ||
const newData = { | ||
...defaultData[0], | ||
name: 'ethusd', | ||
quoteAsset: 'usd', | ||
baseAsset: 'eth', | ||
}; | ||
await masterPairReposity.insertNewPair(newData); | ||
const insertedPairs = await masterPairReposity.find({ | ||
name: newData.name, | ||
}); | ||
expect(insertedPairs.map(getDataFromEntity)).toEqual([newData]); | ||
}); | ||
}); | ||
|
||
describe('insertNewPairs', () => { | ||
it('should insert new pairs', async () => { | ||
const insertedPairs = await masterPairReposity.find(); | ||
expect(insertedPairs.map(getDataFromEntity)).toEqual(defaultData); | ||
}); | ||
}); | ||
|
||
describe('findByPair', () => { | ||
it('should find by pair', async () => { | ||
const existed = await masterPairReposity.findByPair(pair); | ||
expect(existed).toBeDefined(); | ||
expect(getDataFromEntity(existed!)).toEqual(defaultData[0]); | ||
}); | ||
}); | ||
|
||
describe('getPair', () => { | ||
it('should get pair', async () => { | ||
const pairInfo = await masterPairReposity.getPair(); | ||
expect([getDataFromEntity(pairInfo[0])]).toEqual(defaultData); | ||
}); | ||
}); | ||
|
||
describe('getPairNames', () => { | ||
it('should get pair names', async () => { | ||
const pairNames = await masterPairReposity.getPairNames(); | ||
expect(pairNames).toEqual(defaultData.map((o) => o.name)); | ||
}); | ||
}); | ||
|
||
describe('getPrecisionByPair', () => { | ||
it('should get precision by pair', async () => { | ||
const prec = await masterPairReposity.getPrecisionByPair(pair); | ||
expect(prec).toEqual({ pricePrecision: 1, amountPrecision: 0 }); | ||
}); | ||
}); | ||
}); | ||
|
||
function getDataFromEntity(entity: MasterPairEntity): MasterPairEntityCreateParams { | ||
return { | ||
exchange: entity.exchange, | ||
name: entity.name, | ||
baseAsset: entity.baseAsset, | ||
quoteAsset: entity.quoteAsset, | ||
amountPrecision: entity.amountPrecision, | ||
pricePrecision: entity.pricePrecision, | ||
maxOrderAmount: entity.maxOrderAmount, | ||
maxOrderPrice: entity.maxOrderPrice, | ||
isEnabled: entity.isEnabled, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './bitmex'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './bitmex'; | ||
export * from './exchanges'; | ||
export * from './models'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './master-pair.entity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { MasterPairEntityCreateParams } from '@dripjs/models'; | ||
|
||
// use function to avoid object mutating when insert to db | ||
export function getPairDefaultData(): MasterPairEntityCreateParams[] { | ||
return [ | ||
{ | ||
exchange: 'bitmex', | ||
name: 'xbtusd', | ||
baseAsset: 'xbt', | ||
quoteAsset: 'usd', | ||
amountPrecision: 0, | ||
pricePrecision: 1, | ||
maxOrderAmount: 9999999, | ||
maxOrderPrice: 9999999, | ||
isEnabled: true, | ||
}, | ||
]; | ||
} |