-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Statements): Add flexibility for bypassing queue (LLC-1560) (#849)
- Loading branch information
1 parent
052bbce
commit 60451f5
Showing
21 changed files
with
313 additions
and
17 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
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
79 changes: 79 additions & 0 deletions
79
src/apps/statements/expressPresenter/tests/postStatements/bypassQueues.test.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,79 @@ | ||
import * as assert from 'assert'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { xapiHeaderVersion } from '../../../../activities/utils/constants'; | ||
import createClientModel from '../../../tests/utils/createClientModel'; | ||
import createStatement from '../../../tests/utils/createStatement'; | ||
import { jsonContentType, statementsRoute } from '../../../utils/constants'; | ||
import setup from '../../tests/utils/setup'; | ||
import repo from '../../../repo'; | ||
|
||
describe('postStatements', () => { | ||
const { supertest } = setup(); | ||
|
||
it('should throw error for incorrect bypassQueues query param', async () => { | ||
const TEST_ID = '1c86d8e9-f325-404f-b3d9-24c451035586'; | ||
|
||
await supertest | ||
.post(statementsRoute) | ||
.set('Content-Type', jsonContentType) | ||
.set('X-Experience-API-Version', xapiHeaderVersion) | ||
.query({ | ||
bypassQueues: 'abc', | ||
statementId: TEST_ID, | ||
}) | ||
.send([createStatement()]) | ||
.expect((response) => { | ||
assert.equal(response.status, StatusCodes.BAD_REQUEST); | ||
assert.deepEqual(response.body.warnings, [ | ||
`Problem in 'query.bypassQueues'. Received '"abc"'`, | ||
]); | ||
}); | ||
}); | ||
|
||
it('should insert statement with proper bypassQueues query param', async () => { | ||
const TEST_ID = '1c86d8e9-f325-404f-b3d9-24c451035587'; | ||
const TEST_CLIENT = createClientModel(); | ||
const expectedCompletedQueues = ['STATEMENT_QUEUE_1', 'STATEMENT_QUEUE_2']; | ||
|
||
await supertest | ||
.post(statementsRoute) | ||
.set('Content-Type', jsonContentType) | ||
.set('X-Experience-API-Version', xapiHeaderVersion) | ||
.query({ | ||
bypassQueues: expectedCompletedQueues.join(','), | ||
statementId: TEST_ID, | ||
}) | ||
.send([createStatement()]) | ||
.expect(async (response) => { | ||
assert.equal(response.status, StatusCodes.NO_CONTENT); | ||
|
||
const fullStatement = await repo.getStatement({ id: TEST_ID, client: TEST_CLIENT }); | ||
|
||
assert.deepEqual(fullStatement.completedQueues, expectedCompletedQueues); | ||
}); | ||
}); | ||
|
||
it('should insert statement with proper bypassQueues query param (using alternate request)', async () => { | ||
const TEST_ID = '1c86d8e9-f325-404f-b3d9-24c451035588'; | ||
const TEST_CLIENT = createClientModel(); | ||
const expectedCompletedQueues = ['STATEMENT_QUEUE_1', 'STATEMENT_QUEUE_2']; | ||
|
||
await supertest | ||
.post(statementsRoute) | ||
.set('Content-Type', jsonContentType) | ||
.set('X-Experience-API-Version', xapiHeaderVersion) | ||
.query({ | ||
bypassQueues: expectedCompletedQueues.join(','), | ||
statementId: TEST_ID, | ||
method: 'PUT', | ||
}) | ||
.send([createStatement()]) | ||
.expect(async (response) => { | ||
assert.equal(response.status, StatusCodes.NO_CONTENT); | ||
|
||
const fullStatement = await repo.getStatement({ id: TEST_ID, client: TEST_CLIENT }); | ||
|
||
assert.deepEqual(fullStatement.completedQueues, expectedCompletedQueues); | ||
}); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
src/apps/statements/expressPresenter/tests/putStatement/bypassQueues.test.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,55 @@ | ||
import * as assert from 'assert'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { xapiHeaderVersion } from '../../../../activities/utils/constants'; | ||
import createClientModel from '../../../tests/utils/createClientModel'; | ||
import createStatement from '../../../tests/utils/createStatement'; | ||
import { jsonContentType, statementsRoute } from '../../../utils/constants'; | ||
import setup from '../../tests/utils/setup'; | ||
import repo from '../../../repo'; | ||
|
||
describe('putStatement', () => { | ||
const { supertest } = setup(); | ||
|
||
it('should throw error for incorrect bypassQueues query param', async () => { | ||
const TEST_ID = '1c86d8e9-f325-404f-b3d9-24c451035586'; | ||
|
||
await supertest | ||
.put(statementsRoute) | ||
.set('Content-Type', jsonContentType) | ||
.set('X-Experience-API-Version', xapiHeaderVersion) | ||
.query({ | ||
bypassQueues: 'abc', | ||
statementId: TEST_ID, | ||
}) | ||
.send(createStatement()) | ||
.expect((response) => { | ||
assert.equal(response.status, StatusCodes.BAD_REQUEST); | ||
assert.deepEqual(response.body.warnings, [ | ||
`Problem in 'query.bypassQueues'. Received '"abc"'`, | ||
]); | ||
}); | ||
}); | ||
|
||
it('should insert statement with proper bypassQueues query param', async () => { | ||
const TEST_ID = '1c86d8e9-f325-404f-b3d9-24c451035587'; | ||
const TEST_CLIENT = createClientModel(); | ||
const expectedCompletedQueues = ['STATEMENT_QUEUE_1', 'STATEMENT_QUEUE_2']; | ||
|
||
await supertest | ||
.put(statementsRoute) | ||
.set('Content-Type', jsonContentType) | ||
.set('X-Experience-API-Version', xapiHeaderVersion) | ||
.query({ | ||
bypassQueues: expectedCompletedQueues.join(','), | ||
statementId: TEST_ID, | ||
}) | ||
.send(createStatement()) | ||
.expect(async (response) => { | ||
assert.equal(response.status, StatusCodes.NO_CONTENT); | ||
|
||
const fullStatement = await repo.getStatement({ id: TEST_ID, client: TEST_CLIENT }); | ||
|
||
assert.deepEqual(fullStatement.completedQueues, expectedCompletedQueues); | ||
}); | ||
}); | ||
}); |
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,17 @@ | ||
import setupService from 'jscommons/dist/tests/utils/setupService'; | ||
import { SuperTest, Test } from 'supertest'; | ||
import Service from '../../../serviceFactory/Service'; | ||
import service from '../../../utils/testService'; | ||
import supertest from './supertest'; | ||
|
||
const setup = setupService(service); | ||
|
||
export interface Result { | ||
readonly service: Service; | ||
readonly supertest: SuperTest<Test>; | ||
} | ||
|
||
export default (): Result => { | ||
setup(); | ||
return { service, supertest }; | ||
}; |
Oops, something went wrong.