-
Notifications
You must be signed in to change notification settings - Fork 87
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
refactor(verification): migrate verified field #1866
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bc57342
refactor(verification): added new route for verificatino in v3 router
seaerchin a36793d
refactor(public-form/verification): adds new verification endpoint fo…
seaerchin c9d663c
test(public-forms/verification/test): adds unit and integration tests…
seaerchin ef53ca8
refactor(fieldverificationservice): changes frontend to call new endp…
seaerchin 710fbf0
test(fieldverificationservice): updated tests to use new endpoint
seaerchin 6d48ab2
docs(public-forms/verifications/routes/spec): updated test description
seaerchin cf43911
refactor(verification): removed GET /transaction/:transactionId
seaerchin a0a0254
chore(verification/controller): renamed controller function for clarity
seaerchin 57f493a
refactor(fieldverificationservice): add deprecation notice on old route
seaerchin 6af63a7
test(public-forms/verification/routes/spec): updated test to assert r…
seaerchin e4eec85
docs(verification/controller): adds deprecation notice for controller…
seaerchin 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 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
97 changes: 97 additions & 0 deletions
97
src/app/routes/api/v3/forms/__tests__/public-forms.verification.routes.spec.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,97 @@ | ||
import { StatusCodes } from 'http-status-codes' | ||
import session, { Session } from 'supertest-session' | ||
|
||
import { BasicField } from 'src/types' | ||
|
||
import { setupApp } from 'tests/integration/helpers/express-setup' | ||
import { generateDefaultField } from 'tests/unit/backend/helpers/generate-form-data' | ||
import dbHandler from 'tests/unit/backend/helpers/jest-db' | ||
|
||
import { PublicFormsVerificationRouter } from '../public-forms.verification.routes' | ||
|
||
const verificationApp = setupApp('/forms', PublicFormsVerificationRouter) | ||
|
||
jest.mock('nodemailer', () => ({ | ||
createTransport: jest.fn().mockReturnValue({ | ||
sendMail: jest.fn().mockResolvedValue(true), | ||
}), | ||
})) | ||
// Default Twilio export is a function | ||
jest.mock('twilio', () => () => ({ | ||
messages: { | ||
create: jest.fn().mockResolvedValue({ | ||
sid: 'mockSid', | ||
}), | ||
}, | ||
})) | ||
|
||
describe('public-forms.verification.routes', () => { | ||
let mockEmptyFormId: string | ||
let mockVerifiableFormId: string | ||
let request: Session | ||
|
||
beforeAll(async () => await dbHandler.connect()) | ||
|
||
beforeEach(async () => { | ||
request = session(verificationApp) | ||
jest.clearAllMocks() | ||
await dbHandler.clearDatabase() | ||
|
||
// Form without verifiable fields | ||
const { form: emptyForm } = await dbHandler.insertEmailForm() | ||
mockEmptyFormId = String(emptyForm._id) | ||
|
||
// Form with verifiable fields | ||
const emailField = generateDefaultField(BasicField.Email, { | ||
isVerifiable: true, | ||
}) | ||
const mobileField = generateDefaultField(BasicField.Mobile, { | ||
isVerifiable: true, | ||
}) | ||
const { form: verifiableForm } = await dbHandler.insertEmailForm({ | ||
// Alternative mail domain so as not to clash with emptyForm | ||
mailDomain: 'test2.gov.sg', | ||
formOptions: { | ||
form_fields: [emailField, mobileField], | ||
}, | ||
}) | ||
mockVerifiableFormId = String(verifiableForm._id) | ||
}) | ||
|
||
afterAll(async () => await dbHandler.closeDatabase()) | ||
|
||
describe('POST /forms/:formId/fieldverifications', () => { | ||
it('should return 404 when formId is malformed', async () => { | ||
// Act | ||
const response = await request.post(`/forms/malformed/fieldverifications`) | ||
|
||
// Assert | ||
expect(response.status).toBe(StatusCodes.NOT_FOUND) | ||
}) | ||
|
||
it('should return 200 when form has no verifiable fields', async () => { | ||
// Act | ||
const response = await request | ||
// ID of form with no verifiable fields | ||
.post(`/forms/${mockEmptyFormId}/fieldverifications`) | ||
|
||
// Assert | ||
expect(response.status).toBe(StatusCodes.OK) | ||
seaerchin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(response.body).toEqual({}) | ||
}) | ||
|
||
it('should return 201 when form has verifiable fields', async () => { | ||
// Act | ||
const response = await request | ||
// ID of form with verifiable fields | ||
.post(`/forms/${mockVerifiableFormId}/fieldverifications`) | ||
|
||
// Assert | ||
expect(response.status).toBe(StatusCodes.CREATED) | ||
expect(response.body).toEqual({ | ||
transactionId: expect.any(String), | ||
expireAt: expect.any(String), | ||
}) | ||
}) | ||
}) | ||
}) |
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
9 changes: 9 additions & 0 deletions
9
src/app/routes/api/v3/forms/public-forms.verification.routes.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,9 @@ | ||
import { Router } from 'express' | ||
|
||
import * as VerificationController from '../../../../modules/verification/verification.controller' | ||
|
||
export const PublicFormsVerificationRouter = Router() | ||
|
||
PublicFormsVerificationRouter.route( | ||
'/:formId([a-fA-F0-9]{24})/fieldverifications', | ||
).post(VerificationController.handleCreateVerificationTransaction) |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may want to inline this since this is only used in a single test. Same for the verifiable form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't do this cos it'll be reused for the related endpoints in the issues @__@ if it's an issue, i can change it!