-
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
feat(sms-limiting): sms counts retrieval #2276
Conversation
b153443
to
882365c
Compare
Just take note that our current way of manually onboarding users will not trigger this pre-save hook; will need to add another manual check when we do so until we have an automated way to do this on the GUI |
@karrui could you help me understand this? my understanding is that we save the credentials in AWS secrets manager and subsequently, update all forms of the specified user to have the specified message service id. if that's the case, wouldn't this check work because we are checking the form's |
Pre-save hooks don't run when we update using an external GUI such as Robo3T |
i think i'll change this so that the endpoint is rooted at also, i'll rebase this off |
… to add/delete the key
… formsg's credentials
…fault credentials
…e counts and msgsrvcid fix(sms.controller.ts): added mapRouteError for sms controller
… as it sohuld be for the admin
02b0b0f
to
3870a78
Compare
882365c
to
fcb489d
Compare
renamed to smsCountsDto because it is used to transfer data b/w fe and be. against giving it a more specific name because this is a type signifying a transfer of sms count data. context for what this sms counts actually means should be given by the caller
expect(actualSavedObject).toEqual(expected) | ||
}) | ||
|
||
it('should save successfully and set isOnboarded to false when sms is sent using default credentials', async () => { |
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 think we should separate the tests into default -> false, custom -> true tests
…val from sms to admin-form
70ba350
to
9d58ab8
Compare
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.
lgtm, just need to log that one extra error
* feat(sms_count.server.model): adds new isOnboardedAcc key and scripts to add/delete the key * refactor(sms.types): adds property that checks if a sms is sent using formsg's credentials * refactor(sms_count.server.model): adds pre-save hook to automatically set property * feat(sms.types): updated typings of IVerificationsmscount * test(sms_count.server): fixed tests and added extra tests for isOnboardedAccount * feat(sms.service): adds new method to retrieve free sms counts of a user * test(sms.service): adds new unit tests for sms count retrieval * test(sms_count.server.model): updated test case for a client using default credentials * feat(sms.controller): added new sms controller iwth method to retrieve counts and msgsrvcid fix(sms.controller.ts): added mapRouteError for sms controller * feat(routes): exposes new route at sms/:userId/:formId * fix(sms.controller): removed sms count retrieval requiring the userId as it sohuld be for the admin * refactor(sms): count retrieval no longer required userId * test(sms.controller): added unit tests for controller method to retrieve counts * fix(sms.controller): changed to relative imports in spec to avoid e2e tests breaking * refactor(sms_count): sms service wraps model count documents call * test(sms.service): reworked tests to account for mocking of db * refactor(sms.controller): removed extra middleware from sms controller * test(sms.controller.spec): renamed sms controller's exposed method in tests * refactor(sms.routes): removed unused sms route * refactor(sms.controller): changed counts retrieval to be solely focused on counts * feat(admin-forms.form.routes): adds new route for retrieving free sms ocunts for admin of a form * refactor(sms_count): shifts default msgsrvcid to be from config, helper method defined in test * test(sms.controller.spec): updated tests to use mocks * test(sms_count.server.model.spec): updated db tests to use smsConfig * fix(v3.routes): removed extra import statement * refactor(types): renamed smscounts meta and shifted it to api renamed to smsCountsDto because it is used to transfer data b/w fe and be. against giving it a more specific name because this is a type signifying a transfer of sms count data. context for what this sms counts actually means should be given by the caller * test(sms_count.server.model.spec): updated test to use sms_config * docs(sms): updated docs for sms counts retrieval in controller and route * test(sms.service.spec): made tests more explicit * refactor(admin-form.controller): shifts over handler for count retrieval from sms to admin-form * test(admin-form.controller.spec): shifts over associated tests * refactor(sms_count.server.model.spec): changed tests structure * chore(sms.util): removed unneeded method * refactor(sms.types): added in docs for retrieveFreeSmsCounts * fix(admin-forms.form.routes): removed erroneous import * fix(sms.service): adds error logging
* feat(sms_count.server.model): adds new isOnboardedAcc key and scripts to add/delete the key * refactor(sms.types): adds property that checks if a sms is sent using formsg's credentials * refactor(sms_count.server.model): adds pre-save hook to automatically set property * feat(sms.types): updated typings of IVerificationsmscount * test(sms_count.server): fixed tests and added extra tests for isOnboardedAccount * feat(sms.service): adds new method to retrieve free sms counts of a user * test(sms.service): adds new unit tests for sms count retrieval * test(sms_count.server.model): updated test case for a client using default credentials * feat(sms.controller): added new sms controller iwth method to retrieve counts and msgsrvcid fix(sms.controller.ts): added mapRouteError for sms controller * feat(routes): exposes new route at sms/:userId/:formId * fix(sms.controller): removed sms count retrieval requiring the userId as it sohuld be for the admin * refactor(sms): count retrieval no longer required userId * test(sms.controller): added unit tests for controller method to retrieve counts * fix(sms.controller): changed to relative imports in spec to avoid e2e tests breaking * refactor(sms_count): sms service wraps model count documents call * test(sms.service): reworked tests to account for mocking of db * refactor(sms.controller): removed extra middleware from sms controller * test(sms.controller.spec): renamed sms controller's exposed method in tests * refactor(sms.routes): removed unused sms route * refactor(sms.controller): changed counts retrieval to be solely focused on counts * feat(admin-forms.form.routes): adds new route for retrieving free sms ocunts for admin of a form * refactor(sms_count): shifts default msgsrvcid to be from config, helper method defined in test * test(sms.controller.spec): updated tests to use mocks * test(sms_count.server.model.spec): updated db tests to use smsConfig * fix(v3.routes): removed extra import statement * refactor(types): renamed smscounts meta and shifted it to api renamed to smsCountsDto because it is used to transfer data b/w fe and be. against giving it a more specific name because this is a type signifying a transfer of sms count data. context for what this sms counts actually means should be given by the caller * test(sms_count.server.model.spec): updated test to use sms_config * docs(sms): updated docs for sms counts retrieval in controller and route * test(sms.service.spec): made tests more explicit * refactor(admin-form.controller): shifts over handler for count retrieval from sms to admin-form * test(admin-form.controller.spec): shifts over associated tests * refactor(sms_count.server.model.spec): changed tests structure * chore(sms.util): removed unneeded method * refactor(sms.types): added in docs for retrieveFreeSmsCounts * fix(admin-forms.form.routes): removed erroneous import * fix(sms.service): adds error logging
* feat(sms-limiting): sms counts retrieval (#2276) * feat(sms_count.server.model): adds new isOnboardedAcc key and scripts to add/delete the key * refactor(sms.types): adds property that checks if a sms is sent using formsg's credentials * refactor(sms_count.server.model): adds pre-save hook to automatically set property * feat(sms.types): updated typings of IVerificationsmscount * test(sms_count.server): fixed tests and added extra tests for isOnboardedAccount * feat(sms.service): adds new method to retrieve free sms counts of a user * test(sms.service): adds new unit tests for sms count retrieval * test(sms_count.server.model): updated test case for a client using default credentials * feat(sms.controller): added new sms controller iwth method to retrieve counts and msgsrvcid fix(sms.controller.ts): added mapRouteError for sms controller * feat(routes): exposes new route at sms/:userId/:formId * fix(sms.controller): removed sms count retrieval requiring the userId as it sohuld be for the admin * refactor(sms): count retrieval no longer required userId * test(sms.controller): added unit tests for controller method to retrieve counts * fix(sms.controller): changed to relative imports in spec to avoid e2e tests breaking * refactor(sms_count): sms service wraps model count documents call * test(sms.service): reworked tests to account for mocking of db * refactor(sms.controller): removed extra middleware from sms controller * test(sms.controller.spec): renamed sms controller's exposed method in tests * refactor(sms.routes): removed unused sms route * refactor(sms.controller): changed counts retrieval to be solely focused on counts * feat(admin-forms.form.routes): adds new route for retrieving free sms ocunts for admin of a form * refactor(sms_count): shifts default msgsrvcid to be from config, helper method defined in test * test(sms.controller.spec): updated tests to use mocks * test(sms_count.server.model.spec): updated db tests to use smsConfig * fix(v3.routes): removed extra import statement * refactor(types): renamed smscounts meta and shifted it to api renamed to smsCountsDto because it is used to transfer data b/w fe and be. against giving it a more specific name because this is a type signifying a transfer of sms count data. context for what this sms counts actually means should be given by the caller * test(sms_count.server.model.spec): updated test to use sms_config * docs(sms): updated docs for sms counts retrieval in controller and route * test(sms.service.spec): made tests more explicit * refactor(admin-form.controller): shifts over handler for count retrieval from sms to admin-form * test(admin-form.controller.spec): shifts over associated tests * refactor(sms_count.server.model.spec): changed tests structure * chore(sms.util): removed unneeded method * refactor(sms.types): added in docs for retrieveFreeSmsCounts * fix(admin-forms.form.routes): removed erroneous import * fix(sms.service): adds error logging * feat(sms-limiting): prerelease (#2500) * refactor(admin-form/controller): removed env var being sent and changed quota to be on method * refactor(sms.types): updated disableSms to use mongoose types; updated typing of verification schema * fix(sms.config): added missing property
Problem
Part of allowing sms limiting is to have a way to count the number of free sms that an agency user has sent out thus far. Because the frontend also requires this count to determine the appropriate state on the modal, there is also a new endpoint exposed in this PR
Solution
Relevant technical overview (per the design doc) is here
Some relevant technical choices are listed below for discussion
isOnboardedAccount
set using a pre-save hook. This is done so that the updating/setting is automatic, and developers don't have to be concerned with this in the future.SmsController
- decided on this because other controllers don't seem too concerned with the sms counts. Arguably, this could be done onAdminFormController
orUserController
but those seem to be more concerned with the properties of the form/user respectively. (am ok w/ changing if needed tho)Breaking Changes
Manual Tests
Because this endpoint (and method) will be used subsequently to determine whether the form should be disabled or not on the frontend, this needs to be tested for speed.
the test plan is as follows on staging:
/:formId([a-fA-F0-9]{24})/verified-sms/count/free