Skip to content

Commit

Permalink
fix: tests for paginated data
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Dec 14, 2023
1 parent 94816ac commit 482a20e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/integration/unit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('Unit Resource Integration Tests', function () {
.get('/v1/units')
.query({ page: 1, limit: 100 });

const unitRecord = _.head(allUnitsResult.body);
const unitRecord = _.head(allUnitsResult.body.data);

const warehouseUnitIdToSplit = unitRecord.warehouseUnitId;
const newUnitOwner = '35f92331-c8d7-4e9e-a8d2-cd0a86cbb2cf';
Expand Down
50 changes: 24 additions & 26 deletions tests/resources/units.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Units Resource CRUD', function () {
const result = await supertest(app)
.get('/v1/units')
.query({ page: 1, limit: 100 });
response = result.body[0];
response = result.body.data[0];
});

afterEach(async function () {
Expand All @@ -50,15 +50,15 @@ describe('Units Resource CRUD', function () {
.get('/v1/units')
.query({ page: 1, limit: 100 });

expect(result.body.length).to.not.equal(0);
expect(result.body.data.length).to.not.equal(0);
}).timeout(TEST_WAIT_TIME * 10);

it('gets all the units filtered by orgUid', async function () {
const result = await supertest(app)
.get('/v1/units')
.query({ orgUid: response.orgUid, page: 1, limit: 100 });

expect(result.body.length).to.not.equal(1);
expect(result.body.data.length).to.not.equal(1);
// ?orgUid=XXXX
}).timeout(TEST_WAIT_TIME * 10);

Expand All @@ -79,9 +79,11 @@ describe('Units Resource CRUD', function () {
.get('/v1/units')
.query({ order: 'SERIALNUMBER', page: 1, limit: 100 });

expect(result.body[0].serialNumberBlock).to.equal('AAAAA1-AAAAA2');
expect(result.body[1].serialNumberBlock).to.equal('AAAAA11-AAAAA21');
expect(result.body[2].serialNumberBlock).to.equal(
expect(result.body.data[0].serialNumberBlock).to.equal('AAAAA1-AAAAA2');
expect(result.body.data[1].serialNumberBlock).to.equal(
'AAAAA11-AAAAA21',
);
expect(result.body.data[2].serialNumberBlock).to.equal(
'AXJJFSLGHSHEJ1000-AXJJFSLGHSHEJ1010',
);
}).timeout(TEST_WAIT_TIME * 10);
Expand All @@ -92,40 +94,36 @@ describe('Units Resource CRUD', function () {
.get('/v1/units')
.query({ search: 'Certification', page: 1, limit: 100 });

expect(result.body.length).to.not.equal(1);
expect(result.body.data.length).to.not.equal(1);
}).timeout(TEST_WAIT_TIME * 10);
it('gets all the units for a search term filtered by orgUid', async function () {
// ?orgUid=XXXX&search=XXXX
const result = await supertest(app)
.get('/v1/units')
.query({
orgUid: response.orgUid,
search: 'Certification',
page: 1,
limit: 100,
});

expect(result.body.length).to.not.equal(1);
const result = await supertest(app).get('/v1/units').query({
orgUid: response.orgUid,
search: 'Certification',
page: 1,
limit: 100,
});

expect(result.body.data.length).to.not.equal(1);
}).timeout(TEST_WAIT_TIME * 10);
it('gets optional paginated results', async function () {
// ?page=X&limit=10
const result = await supertest(app)
.get('/v1/units')
.query({ page: 1, limit: 1 });

expect(result.body.length).to.not.equal(1);
expect(result.body.data.length).to.not.equal(1);
}).timeout(TEST_WAIT_TIME * 10);
it('finds a single result by warehouseUnitId', async function () {
// ?warehouseUnitId=XXXX
const result = await supertest(app)
.get('/v1/units')
.query({
warehouseUnitId: response.warehouseUnitId,
page: 1,
limit: 100,
});
const result = await supertest(app).get('/v1/units').query({
warehouseUnitId: response.warehouseUnitId,
page: 1,
limit: 100,
});

expect(result.body.length).to.not.equal(1);
expect(result.body.data.length).to.not.equal(1);
}).timeout(TEST_WAIT_TIME * 10);
});
});
Expand Down

0 comments on commit 482a20e

Please sign in to comment.