-
Notifications
You must be signed in to change notification settings - Fork 2
Added Unit Tests #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TechManTejas
wants to merge
5
commits into
verifiable-presentation:trunk
Choose a base branch
from
TechManTejas:trunk
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4b7527a
added unit tests
TechManTejas 5a9f824
ci: add separate `test:unit` step in workflow
gamemaker1 29c36a5
Update test/suites/unit.ts
TechManTejas 80140d8
JSON to json and preetier
TechManTejas 71cff13
Merge branch 'trunk' of https://github.com/TechManTejas/identity into…
TechManTejas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| { | ||
| "identifier": { | ||
| "type": "email", | ||
| "properties": { | ||
| "email": 0 | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,6 @@ | ||
| { | ||
| "identifier": { | ||
| "type": "email", | ||
| "properties": "not an object" | ||
| } | ||
| } |
This file contains hidden or 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,3 @@ | ||
| { | ||
| "identifier": "notobject" | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "identifier": { | ||
| "type"= "email", | ||
| "properties": { | ||
| "email"="techmantejas@gmail.com" | ||
| } | ||
| } | ||
| } |
Empty file.
This file contains hidden or 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,6 @@ | ||
| { | ||
| "identifier": { | ||
| "type": "email", | ||
| "properties": {} | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| {} |
This file contains hidden or 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,5 @@ | ||
| { | ||
| "identifier": { | ||
| "type": "email" | ||
| } | ||
| } |
This file contains hidden or 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,3 @@ | ||
| { | ||
| "identifier": {} | ||
| } |
This file contains hidden or 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,221 @@ | ||
| // tests/suites/unit.ts | ||
| // The file contains the unit test suite. | ||
|
|
||
| import type { FastifyInstance } from 'fastify' | ||
| import type { TestFn } from 'ava' | ||
|
|
||
| // eslint-disable-next-line ava/use-test | ||
| import ava from 'ava' | ||
|
|
||
| import { fixture } from '../helpers/fixtures.js' | ||
|
|
||
| import { build } from '../../source/loaders/index.js' | ||
| import { ServerError } from '../../source/utilities/errors.js' | ||
|
|
||
| type ServerContext = { | ||
| server: FastifyInstance | ||
| } | ||
|
|
||
| const test = ava as TestFn<ServerContext> | ||
| const json = JSON | ||
|
|
||
| // Create the server before running the tests. | ||
| test.before(async (t) => { | ||
| t.context.server = build({ disableRequestLogging: true }) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [no body]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| // Json.stringify() is used over here to ensure that the empty file is considered as a valid JSON | ||
| payload: json.stringify(fixture('no-body')), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the body must be object type. | ||
| t.regex(error?.message, /body must be object/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [no identifier]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('no-identifier'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the no identifier type. | ||
| t.regex(error?.message, /identifier/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [invalid identifier]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('invalid-identifier'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the invalid identifier type. | ||
| t.regex(error?.message, /identifier/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [no type]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('no-type'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the no type type. | ||
| t.regex(error?.message, /type/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [no properties]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('no-properties'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the no properties type. | ||
| t.regex(error?.message, /properties/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [invalid identifier properties]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('invalid-identifier-properties'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the invalid identifier properties type. | ||
| t.regex(error?.message, /identifier\/properties must be object/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [no external identifier]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('no-external-identifier'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the no external identifier type. | ||
| t.regex( | ||
| error?.message, | ||
| /The properties for the external identifier were missing or incomplete/, | ||
| ) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 400 improper-payload [invalid identifier properties email]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('invalid-identifier-properties-email'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('improper-payload') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the invalid identifier properties email type. | ||
| t.regex( | ||
| error?.message, | ||
| /The properties for the external identifier were missing or incomplete/, | ||
| ) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
|
||
| test('unit | post /identity | 500 server-crash [invalid json]', async (t) => { | ||
| const response = await t.context.server.inject({ | ||
| method: 'post', | ||
| url: '/identity', | ||
| payload: fixture('invalid-json'), | ||
| headers: { 'content-type': 'application/json' }, | ||
| }) | ||
|
|
||
| const { meta, error, data } = json.parse(response.payload) | ||
| const expectedError = new ServerError('server-crash') | ||
|
|
||
| // Check that the request failed with the expected HTTP status code and | ||
| // error code. | ||
| t.is(meta?.status, expectedError.status) | ||
| t.is(error?.code, expectedError.code) | ||
| // Check that the message is related to the invalid identifier properties email type. | ||
| t.regex(error?.message, /An unexpected error occurred/) | ||
| // Check that only the `error` and `meta` fields were returned. | ||
| t.is(data, undefined) | ||
| }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the test cases you have added so far are great! Just a few more that you could add:
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.