-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for usageEngine and usage routes
- Loading branch information
Showing
7 changed files
with
205 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
describe('unit tests', function () { | ||
require('./capacityEngine'); | ||
require('./quoteEngine'); | ||
require('./usageEngine'); | ||
require('./routes'); | ||
require('./calculateOptimalPoolAllocation'); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
describe('routes', function () { | ||
require('./quote'); | ||
require('./capcaity'); | ||
require('./usage'); | ||
}); |
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,23 @@ | ||
const { expect } = require('chai'); | ||
const supertest = require('supertest'); | ||
const initApp = require('../../mocks/server'); | ||
const { usage } = require('../responses'); | ||
|
||
describe('GET /usage', async () => { | ||
let server; | ||
before(() => { | ||
const app = initApp(); | ||
server = supertest(app); | ||
}); | ||
|
||
it('should get all usage for pools', async function () { | ||
const { body: response } = await server.get('/v2/usage').expect('Content-Type', /json/).expect(200); | ||
expect(response).to.be.deep.equal(usage); | ||
}); | ||
|
||
it('should get all usage for one pool', async function () { | ||
const poolId = 1; | ||
const { body: response } = await server.get(`/v2/usage/${poolId}`).expect('Content-Type', /json/).expect(200); | ||
expect(response).to.be.deep.equal(usage[0]); | ||
}); | ||
}); |
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,52 @@ | ||
const sinon = require('sinon'); | ||
const { expect } = require('chai'); | ||
const { BigNumber } = require('ethers'); | ||
|
||
const usageEngine = require('../../src/lib/usageEngine'); | ||
const mockStore = require('../mocks/store'); | ||
const { usage } = require('./responses'); | ||
describe.only('Capacity Engine tests', () => { | ||
const store = { getState: () => null }; | ||
|
||
afterEach(function () { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should return usage for all pools', () => { | ||
sinon.stub(store, 'getState').callsFake(() => mockStore); | ||
const response = usageEngine(store, []); | ||
|
||
response.forEach((pool, i) => { | ||
expect(pool.poolId).to.be.equal(usage[i].poolId); | ||
pool.products.forEach(({ productId, capacityUsed }, j) => { | ||
expect(productId).to.be.equal(usage[i].products[j].productId); | ||
capacityUsed.forEach(({ amount }, k) => { | ||
expect(amount.toString()).to.be.equal(usage[i].products[j].capacityUsed[k].amount); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should return capacity for one product', () => { | ||
sinon.stub(store, 'getState').callsFake(() => mockStore); | ||
|
||
const [pool] = usageEngine(store, ['1']); | ||
const [expectedUsage] = usage; | ||
|
||
expect(pool.poolId).to.be.equal(expectedUsage.poolId); | ||
pool.products.forEach(({ productId, capacityUsed }, i) => { | ||
expect(productId).to.be.equal(expectedUsage.products[i].productId); | ||
capacityUsed.forEach(({ amount }, j) => { | ||
expect(amount.toString()).to.be.equal(expectedUsage.products[j].capacityUsed[j].amount); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should throw non existing product', () => { | ||
sinon.stub(store, 'getState').callsFake(() => mockStore); | ||
|
||
const [pool] = usageEngine(store, ['10']); | ||
|
||
expect(pool.products.length).to.be.equal(0); | ||
}); | ||
}); |