-
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 #50 from commercetools/kinghin.leung/add-test-cases
chore(processor) - add unit test cases for adyen-payment service
- Loading branch information
Showing
15 changed files
with
7,738 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ jobs: | |
run: npm run build | ||
|
||
- name: Execute tests | ||
run: npm run test | ||
run: npm run test -- --coverage |
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 |
---|---|---|
|
@@ -21,3 +21,6 @@ dist-ssr | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# test converage | ||
coverage/* |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ module.exports = { | |
testEnvironment: 'node', | ||
setupFiles: ['./src/jest.setup.ts'], | ||
roots: ['./test'], | ||
}; | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { afterEach, beforeEach, describe, expect, test } from '@jest/globals'; | ||
import Fastify, { type FastifyInstance, FastifyError } from 'fastify'; | ||
import { errorHandler } from '../../../src/libs/fastify/error-handler'; | ||
import { ErrorAuthErrorResponse, Errorx, ErrorxAdditionalOpts } from '@commercetools/connect-payments-sdk'; | ||
import { requestContextPlugin } from '../../../src/libs/fastify/context/context'; | ||
import { FastifySchemaValidationError } from 'fastify/types/schema'; | ||
|
||
describe('error-handler', () => { | ||
let fastify: FastifyInstance; | ||
beforeEach(async () => { | ||
fastify = Fastify(); | ||
fastify.setErrorHandler(errorHandler); | ||
await fastify.register(requestContextPlugin); | ||
}); | ||
|
||
afterEach(async () => { | ||
await fastify.close(); | ||
}); | ||
|
||
test('errox error', async () => { | ||
fastify.get('/', () => { | ||
throw new Errorx({ | ||
code: 'ErrorCode', | ||
message: 'someMessage', | ||
httpErrorStatus: 404, | ||
}); | ||
}); | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
|
||
expect(response.json()).toStrictEqual({ | ||
message: 'someMessage', | ||
statusCode: 404, | ||
errors: [ | ||
{ | ||
code: 'ErrorCode', | ||
message: 'someMessage', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('errox with fields', async () => { | ||
fastify.get('/', () => { | ||
throw new Errorx({ | ||
code: 'ErrorCode', | ||
message: 'someMessage', | ||
httpErrorStatus: 404, | ||
fields: { | ||
test: 'field1', | ||
}, | ||
}); | ||
}); | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
|
||
expect(response.json()).toStrictEqual({ | ||
message: 'someMessage', | ||
statusCode: 404, | ||
errors: [ | ||
{ | ||
code: 'ErrorCode', | ||
message: 'someMessage', | ||
test: 'field1', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('general error', async () => { | ||
fastify.get('/', () => { | ||
throw new Error('some message goes here'); | ||
}); | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
|
||
expect(response.json()).toStrictEqual({ | ||
message: 'Internal server error.', | ||
statusCode: 500, | ||
errors: [ | ||
{ | ||
code: 'General', | ||
message: 'Internal server error.', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('Fastify error with missing required field', async () => { | ||
const validationError: FastifySchemaValidationError = { | ||
keyword: 'required', | ||
instancePath: 'instancePath/domain/value', | ||
schemaPath: 'schemaPath/domain/value', | ||
params: { | ||
missingProperty: 'dummy-field', | ||
}, | ||
message: 'fastify-error-message', | ||
}; | ||
const fastifyError: FastifyError = { | ||
code: 'ErrorCode', | ||
name: 'fastify-error', | ||
message: 'fastify-error-message', | ||
validation: [validationError], | ||
}; | ||
fastify.get('/', () => { | ||
throw fastifyError; | ||
}); | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
expect(response.json()).toStrictEqual({ | ||
message: 'A value is required for field dummy-field.', | ||
statusCode: 400, | ||
errors: [ | ||
{ | ||
code: 'RequiredField', | ||
field: 'dummy-field', | ||
message: 'A value is required for field dummy-field.', | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
test('ErrorAuthErrorResponse', async () => { | ||
const opts: ErrorxAdditionalOpts = { | ||
privateFields: {}, | ||
privateMessage: '', | ||
fields: {}, | ||
skipLog: true, | ||
cause: undefined, | ||
}; | ||
const authErrorResponse: ErrorAuthErrorResponse = new ErrorAuthErrorResponse('someMessage', opts, '401'); | ||
|
||
fastify.get('/', () => { | ||
throw authErrorResponse; | ||
}); | ||
|
||
const response = await fastify.inject({ | ||
method: 'GET', | ||
url: '/', | ||
}); | ||
expect(response.json()).toStrictEqual({ | ||
message: 'someMessage', | ||
statusCode: 401, | ||
errors: [ | ||
{ | ||
code: '401', | ||
message: 'someMessage', | ||
}, | ||
], | ||
error: '401', | ||
error_description: 'someMessage', | ||
}); | ||
}); | ||
}); |
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,9 @@ | ||
import { describe, test, expect } from '@jest/globals'; | ||
|
||
describe('sample-test-suite', () => { | ||
// Please customize test cases below | ||
test('sample-test-case', async () => { | ||
const result = {}; | ||
expect(result).toStrictEqual({}); | ||
}); | ||
}); |
Oops, something went wrong.