Skip to content

Commit

Permalink
test: add test cases for global limit
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Apr 28, 2024
1 parent b6af83a commit 897846f
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,63 @@ describe('admin-form.payment.service', () => {
InvalidPaymentAmountError,
)
})

it('should return OK if min_amount is greater than global_min_amount_override', async () => {
const updatedPaymentSettingsMaxAboveMin = {
...defaultVariablePaymentSettings,
min_amount: 10,
max_amount: 1500,
global_min_amount_override: 10,
}

const mockUpdatedForm = {
_id: mockFormId,
payments_field: updatedPaymentSettingsMaxAboveMin,
}
const putSpy = jest
.spyOn(EncryptFormModel, 'updatePaymentsById')
.mockResolvedValueOnce(
mockUpdatedForm as unknown as IEncryptedFormDocument,
)
// Act
const actualResult = await AdminFormPaymentService.updatePayments(
mockFormId,
updatedPaymentSettingsMaxAboveMin,
)

// Assert
expect(putSpy).toHaveBeenCalledWith(
mockFormId,
updatedPaymentSettingsMaxAboveMin,
)
expect(actualResult.isOk()).toBeTrue()
expect(actualResult._unsafeUnwrap()).toEqual(
updatedPaymentSettingsMaxAboveMin,
)
})

it('should return error if min_amount is lower than global_min_amount_override', async () => {
const updatedPaymentSettingsMaxAboveMin = {
...defaultVariablePaymentSettings,
min_amount: 9,
max_amount: 1500,
global_min_amount_override: 10,
}

const putSpy = jest.spyOn(EncryptFormModel, 'updatePaymentsById')
// Act
const actualResult = await AdminFormPaymentService.updatePayments(
mockFormId,
updatedPaymentSettingsMaxAboveMin,
)

// Assert
expect(putSpy).not.toHaveBeenCalled()
expect(actualResult.isErr()).toBeTrue()
expect(actualResult._unsafeUnwrapErr()).toBeInstanceOf(
InvalidPaymentAmountError,
)
})
})
})

Expand Down

0 comments on commit 897846f

Please sign in to comment.