-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from ember-nexus/github-issue/93
GitHub issue/93
- Loading branch information
Showing
30 changed files
with
773 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
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
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
41 changes: 41 additions & 0 deletions
41
test/Unit/Endpoint/User/PostChangePasswordEndpoint/PostChangePasswordEndpoint204.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,41 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
return new HttpResponse(null, { | ||
status: 204, | ||
headers: {}, | ||
}); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle node response', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await Container.get(PostChangePasswordEndpoint).postChangePassword( | ||
uniqueUserIdentifier, | ||
currentPassword, | ||
newPassword, | ||
); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
mockServer.close(); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...dpoint/User/PostChangePasswordEndpoint/PostChangePasswordEndpointBadResponseError.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,45 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { ParseError } from '../../../../../src/Error'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
return HttpResponse.text('Some content which can not be interpreted as JSON.', { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'text/plain; charset=utf-8', | ||
}, | ||
}); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle bad response error', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await expect( | ||
Container.get(PostChangePasswordEndpoint).postChangePassword(uniqueUserIdentifier, currentPassword, newPassword), | ||
).to.eventually.be.rejectedWith(ParseError); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
expect(testLogger.assertErrorHappened("Unable to parse response as content type is not 'application/problem+json'.")) | ||
.to.be.true; | ||
|
||
mockServer.close(); | ||
}); |
39 changes: 39 additions & 0 deletions
39
...t/Endpoint/User/PostChangePasswordEndpoint/PostChangePasswordEndpointNetworkError.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,39 @@ | ||
import { expect } from 'chai'; | ||
import { http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { NetworkError } from '../../../../../src/Error'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
return Response.error(); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle network error', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await expect( | ||
Container.get(PostChangePasswordEndpoint).postChangePassword(uniqueUserIdentifier, currentPassword, newPassword), | ||
).to.eventually.be.rejectedWith(NetworkError); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
expect(testLogger.assertErrorHappened('Experienced generic network error during creating resource.')).to.be.true; | ||
|
||
mockServer.close(); | ||
}); |
43 changes: 43 additions & 0 deletions
43
...r/PostChangePasswordEndpoint/PostChangePasswordEndpointNoContentTypeResponseError.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,43 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { ParseError } from '../../../../../src/Error'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
const response = HttpResponse.text('Some content which can not be interpreted as JSON.', { | ||
status: 200, | ||
}); | ||
response.headers.delete('Content-Type'); | ||
return response; | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle no content type response error', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await expect( | ||
Container.get(PostChangePasswordEndpoint).postChangePassword(uniqueUserIdentifier, currentPassword, newPassword), | ||
).to.eventually.be.rejectedWith(ParseError); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
expect(testLogger.assertErrorHappened('Response does not contain content type header.')).to.be.true; | ||
|
||
mockServer.close(); | ||
}); |
52 changes: 52 additions & 0 deletions
52
...r/PostChangePasswordEndpoint/PostChangePasswordEndpointTooManyRequests429Response.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,52 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { Response429TooManyRequestsError } from '../../../../../src/Error'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'http://ember-nexus-api/error/429/too-many-requests', | ||
title: 'Unauthorized', | ||
status: 429, | ||
detail: 'wip', | ||
}, | ||
{ | ||
status: 429, | ||
headers: { | ||
'Content-Type': 'application/problem+json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle bad response error', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await expect( | ||
Container.get(PostChangePasswordEndpoint).postChangePassword(uniqueUserIdentifier, currentPassword, newPassword), | ||
).to.eventually.be.rejectedWith(Response429TooManyRequestsError); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
expect(testLogger.assertErrorHappened('Server returned 429 too many requests.')).to.be.true; | ||
|
||
mockServer.close(); | ||
}); |
53 changes: 53 additions & 0 deletions
53
...User/PostChangePasswordEndpoint/PostChangePasswordEndpointUnauthorized401Response.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,53 @@ | ||
import { expect } from 'chai'; | ||
import { HttpResponse, http } from 'msw'; | ||
import { setupServer } from 'msw/node'; | ||
import { Container } from 'typedi'; | ||
|
||
import { PostChangePasswordEndpoint } from '../../../../../src/Endpoint/User'; | ||
import { Response401UnauthorizedError } from '../../../../../src/Error'; | ||
import { Logger, WebSdkConfiguration } from '../../../../../src/Service'; | ||
import { createUniqueUserIdentifierFromString } from '../../../../../src/Type/Definition'; | ||
import { TestLogger } from '../../../TestLogger'; | ||
|
||
const mockServer = setupServer( | ||
http.post('http://mock-api/change-password', () => { | ||
return HttpResponse.json( | ||
{ | ||
type: 'http://ember-nexus-api/error/401/unauthorized', | ||
title: 'Unauthorized', | ||
status: 401, | ||
detail: | ||
"Authorization for the request failed due to possible problems with the token (incorrect or expired), password (incorrect or changed), the user's unique identifier, or the user's status (e.g., missing, blocked, or deleted).", | ||
}, | ||
{ | ||
status: 401, | ||
headers: { | ||
'Content-Type': 'application/problem+json; charset=utf-8', | ||
}, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
const testLogger: TestLogger = new TestLogger(); | ||
Container.set(Logger, testLogger); | ||
Container.get(WebSdkConfiguration).setApiHost('http://mock-api'); | ||
|
||
test('PostChangePasswordEndpoint should handle unauthorized response error', async () => { | ||
mockServer.listen(); | ||
|
||
const uniqueUserIdentifier = createUniqueUserIdentifierFromString('[email protected]'); | ||
const currentPassword = '1234'; | ||
const newPassword = '4321'; | ||
|
||
await expect( | ||
Container.get(PostChangePasswordEndpoint).postChangePassword(uniqueUserIdentifier, currentPassword, newPassword), | ||
).to.eventually.be.rejectedWith(Response401UnauthorizedError); | ||
|
||
expect(testLogger.assertDebugHappened('Executing HTTP POST request against url http://mock-api/change-password .')).to | ||
.be.true; | ||
|
||
expect(testLogger.assertErrorHappened('Server returned 401 unauthorized.')).to.be.true; | ||
|
||
mockServer.close(); | ||
}); |
Oops, something went wrong.