Skip to content
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

build: release v6.108.0 #7067

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.108.0](https://github.com/opengovsg/FormSG/compare/v6.107.0...v6.108.0)

- feat(payment): webhook with charge information [`#7058`](https://github.com/opengovsg/FormSG/pull/7058)
- build: merge release v6.107.0 into develop [`#7064`](https://github.com/opengovsg/FormSG/pull/7064)
- build: release v6.107.0 [`#7063`](https://github.com/opengovsg/FormSG/pull/7063)

#### [v6.107.0](https://github.com/opengovsg/FormSG/compare/v6.106.0...v6.107.0)

> 5 February 2024

- feat: add Not Applicable to MyInfo occupations list [`#7032`](https://github.com/opengovsg/FormSG/pull/7032)
- chore: sync frontend package version with root [`#7061`](https://github.com/opengovsg/FormSG/pull/7061)
- chore: update readme for installing virus-scanner packages [`#7062`](https://github.com/opengovsg/FormSG/pull/7062)
- fix: recaptcha cn [`#7059`](https://github.com/opengovsg/FormSG/pull/7059)
- build: merge release v6.106.0 into develop [`#7060`](https://github.com/opengovsg/FormSG/pull/7060)
- build: release v6.106.0 [`#7055`](https://github.com/opengovsg/FormSG/pull/7055)
- chore: bump version to v6.107.0 [`5b490e0`](https://github.com/opengovsg/FormSG/commit/5b490e0e1c5741a7c46e2e37f0ec39e8700ba4b0)

#### [v6.106.0](https://github.com/opengovsg/FormSG/compare/v6.105.0...v6.106.0)

Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-frontend",
"version": "6.107.0",
"version": "6.108.0",
"homepage": ".",
"private": true,
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "FormSG",
"description": "Form Manager for Government",
"version": "6.107.0",
"version": "6.108.0",
"homepage": "https://form.gov.sg",
"authors": [
"FormSG <[email protected]>"
Expand Down
206 changes: 200 additions & 6 deletions src/app/models/__tests__/submission.server.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import getSubmissionModel, {
import {
BasicField,
FormAuthType,
PaymentType,
SubmissionType,
WebhookResponse,
} from '../../../../shared/types'
import { ISubmissionSchema } from '../../../../src/types'
import getPaymentModel from '../payment.server.model'

jest.mock('dns', () => ({
promises: {
Expand All @@ -27,6 +29,7 @@ const MockDns = jest.mocked(dns)
const Submission = getSubmissionModel(mongoose)
const EncryptedSubmission = getEncryptSubmissionModel(mongoose)
const EmailSubmission = getEmailSubmissionModel(mongoose)
const PaymentSubmission = getPaymentModel(mongoose)

// TODO: Add more tests for the rest of the submission schema.
describe('Submission Model', () => {
Expand Down Expand Up @@ -265,6 +268,132 @@ describe('Submission Model', () => {
verifiedContent: undefined,
version: 0,
created: submission.created,
paymentContent: {},
},
},
})
})

it('should return the paymentContent when the submission, payment, and webhook URL exist', async () => {
const { form } = await dbHandler.insertEncryptForm({
formOptions: {
webhook: {
url: MOCK_WEBHOOK_URL,
isRetryEnabled: true,
},
},
})
const submission = await EncryptedSubmission.create({
form: form._id,
encryptedContent: MOCK_ENCRYPTED_CONTENT,
version: 0,
})

const MOCK_PAYMENT_INTENT_ID = 'MOCK_PAYMENT_INTENT_ID'
const MOCK_EMAIL = 'MOCK_EMAIL'
const MOCK_PAYMENT_STATUS = 'succeeded'
const payment = await PaymentSubmission.create({
amount: 100,
paymentStatus: 'successful',
submission: submission._id,
gstEnabled: false,
paymentIntentId: MOCK_PAYMENT_INTENT_ID,
email: MOCK_EMAIL,
targetAccountId: 'targetAccountId',
formId: form._id,
pendingSubmissionId: submission._id,
status: MOCK_PAYMENT_STATUS,
})
submission.paymentId = payment._id
await submission.save()

const result = await EncryptedSubmission.retrieveWebhookInfoById(
String(submission._id),
)

expect(result).toEqual({
webhookUrl: MOCK_WEBHOOK_URL,
isRetryEnabled: true,
webhookView: {
data: {
attachmentDownloadUrls: {},
formId: String(form._id),
submissionId: String(submission._id),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: undefined,
version: 0,
created: submission.created,
paymentContent: {
amount: '1.00',
dateTime: '-',
payer: MOCK_EMAIL,
paymentIntent: MOCK_PAYMENT_INTENT_ID,
productService: '-',
status: MOCK_PAYMENT_STATUS,
transactionFee: '-',
type: 'payment_charge',
url: expect.stringContaining(
`api/v3/payments/${form._id}/${payment._id}/invoice/download`,
),
},
},
},
})
})

it('should not return the paymentContent when the payment type is Fixed', async () => {
const { form } = await dbHandler.insertEncryptForm({
formOptions: {
webhook: {
url: MOCK_WEBHOOK_URL,
isRetryEnabled: true,
},
},
})
const submission = await EncryptedSubmission.create({
form: form._id,
encryptedContent: MOCK_ENCRYPTED_CONTENT,
version: 0,
})

const MOCK_PAYMENT_INTENT_ID = 'MOCK_PAYMENT_INTENT_ID'
const MOCK_EMAIL = 'MOCK_EMAIL'
const MOCK_PAYMENT_STATUS = 'succeeded'
const payment = await PaymentSubmission.create({
amount: 100,
paymentStatus: 'successful',
submission: submission._id,
gstEnabled: false,
paymentIntentId: MOCK_PAYMENT_INTENT_ID,
email: MOCK_EMAIL,
targetAccountId: 'targetAccountId',
formId: form._id,
pendingSubmissionId: submission._id,
status: MOCK_PAYMENT_STATUS,
payment_fields_snapshot: {
payment_type: PaymentType.Fixed,
},
})
submission.paymentId = payment._id
await submission.save()

const result = await EncryptedSubmission.retrieveWebhookInfoById(
String(submission._id),
)

expect(result).toEqual({
webhookUrl: MOCK_WEBHOOK_URL,
isRetryEnabled: true,
webhookView: {
data: {
attachmentDownloadUrls: {},
formId: String(form._id),
submissionId: String(submission._id),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: undefined,
version: 0,
created: submission.created,
paymentContent: {},
},
},
})
Expand Down Expand Up @@ -318,6 +447,7 @@ describe('Submission Model', () => {
verifiedContent: undefined,
version: 0,
created: submission.created,
paymentContent: {},
},
},
})
Expand Down Expand Up @@ -354,6 +484,7 @@ describe('Submission Model', () => {
verifiedContent: undefined,
version: 0,
created: submission.created,
paymentContent: {},
},
},
})
Expand All @@ -365,7 +496,7 @@ describe('Submission Model', () => {
// Arrange
const formCounts = [4, 2, 4]
const formIdsAndCounts = times(formCounts.length, (it) => ({
_id: mongoose.Types.ObjectId(),
_id: new mongoose.Types.ObjectId(),
count: formCounts[it],
}))
const submissionPromises: Promise<ISubmissionSchema>[] = []
Expand Down Expand Up @@ -401,7 +532,7 @@ describe('Submission Model', () => {
// Arrange
const formCounts = [1, 1, 2]
const formIdsAndCounts = times(formCounts.length, (it) => ({
_id: mongoose.Types.ObjectId(),
_id: new mongoose.Types.ObjectId(),
count: formCounts[it],
}))
const submissionPromises: Promise<ISubmissionSchema>[] = []
Expand Down Expand Up @@ -436,6 +567,66 @@ describe('Submission Model', () => {

describe('Methods', () => {
describe('getWebhookView', () => {
it('should returnt non-null view with paymentContent when submission has paymentId', async () => {
const formId = new ObjectId()

const submission = await EncryptedSubmission.create({
submissionType: SubmissionType.Encrypt,
form: formId,
encryptedContent: MOCK_ENCRYPTED_CONTENT,
version: 1,
authType: FormAuthType.NIL,
myInfoFields: [],
webhookResponses: [],
})

const MOCK_PAYMENT_INTENT_ID = 'MOCK_PAYMENT_INTENT_ID'
const MOCK_EMAIL = 'MOCK_EMAIL'
const MOCK_PAYMENT_STATUS = 'succeeded'
const payment = await PaymentSubmission.create({
amount: 100,
paymentStatus: 'successful',
submission: submission._id,
gstEnabled: false,
paymentIntentId: MOCK_PAYMENT_INTENT_ID,
email: MOCK_EMAIL,
targetAccountId: 'targetAccountId',
formId: formId,
pendingSubmissionId: submission._id,
status: MOCK_PAYMENT_STATUS,
})
submission.paymentId = payment._id
await submission.save()

// Act
const actualWebhookView = await submission.getWebhookView()

// Assert
expect(actualWebhookView).toEqual({
data: {
formId: expect.any(String),
submissionId: expect.any(String),
created: expect.any(Date),
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: undefined,
attachmentDownloadUrls: {},
version: 1,
paymentContent: {
amount: '1.00',
dateTime: '-',
payer: MOCK_EMAIL,
paymentIntent: MOCK_PAYMENT_INTENT_ID,
productService: '-',
status: MOCK_PAYMENT_STATUS,
transactionFee: '-',
type: 'payment_charge',
url: expect.stringContaining(
`api/v3/payments/${formId}/${payment._id}/invoice/download`,
),
},
},
})
})
it('should return non-null view with encryptedSubmission type when submission has no verified content', async () => {
// Arrange
const formId = new ObjectId()
Expand All @@ -451,7 +642,7 @@ describe('Submission Model', () => {
})

// Act
const actualWebhookView = submission.getWebhookView()
const actualWebhookView = await submission.getWebhookView()

// Assert
expect(actualWebhookView).toEqual({
Expand All @@ -463,6 +654,7 @@ describe('Submission Model', () => {
verifiedContent: undefined,
attachmentDownloadUrls: {},
version: 1,
paymentContent: {},
},
})
})
Expand All @@ -483,7 +675,7 @@ describe('Submission Model', () => {
})

// Act
const actualWebhookView = submission.getWebhookView()
const actualWebhookView = await submission.getWebhookView()

// Assert
expect(actualWebhookView).toEqual({
Expand All @@ -495,6 +687,7 @@ describe('Submission Model', () => {
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: MOCK_VERIFIED_CONTENT,
version: 1,
paymentContent: {},
},
})
})
Expand Down Expand Up @@ -526,7 +719,7 @@ describe('Submission Model', () => {
).populate('form', 'webhook')

// Act
const actualWebhookView = populatedSubmission!.getWebhookView()
const actualWebhookView = await populatedSubmission!.getWebhookView()

// Assert
expect(actualWebhookView).toEqual({
Expand All @@ -538,6 +731,7 @@ describe('Submission Model', () => {
encryptedContent: MOCK_ENCRYPTED_CONTENT,
verifiedContent: MOCK_VERIFIED_CONTENT,
version: 1,
paymentContent: {},
},
})
})
Expand All @@ -559,7 +753,7 @@ describe('Submission Model', () => {
})

// Act
const actualWebhookView = submission.getWebhookView()
const actualWebhookView = await submission.getWebhookView()

// Assert
expect(actualWebhookView).toBeNull()
Expand Down
Loading
Loading