Skip to content

Commit

Permalink
feat: add local dev support for twilio (#5881)
Browse files Browse the repository at this point in the history
* feat: add prism for twilio

* feat: add localdev env config

* fix: mocktwilio randomly assigning errorCode in response

* feat: route sms body to maildev

* fix: incorrect refernce to determine localdev

* refactor: rename localDev to useMockTwilio

* feat: generalize sendLocalDevMail

* fix: test cases not mocking new mocktwilio
  • Loading branch information
KenLSM authored May 12, 2023
1 parent 2c457d2 commit cb2943a
Show file tree
Hide file tree
Showing 14 changed files with 2,327 additions and 394 deletions.
6 changes: 5 additions & 1 deletion .template-env
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ FORMSG_SDK_MODE=

## Per-minute, per-IP request limits applied to specific endpoints
# SUBMISSIONS_RATE_LIMIT=
# SEND_AUTH_OTP_RATE_LIMIT=
# SEND_AUTH_OTP_RATE_LIMIT=

# Used to check if BE Server is currently running on local development environment
# One of boolean: "true" | "false"
# USE_MOCK_TWILIO=
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ services:
# https://github.com/opengovsg/formsg-javascript-sdk/blob/develop/src/resource/signing-keys.ts
- SIGNING_SECRET_KEY=HDBXpu+2/gu10bLHpy8HjpN89xbA6boH9GwibPGJA8BOXmB+zOUpxCP33/S5p8vBWlPokC7gLR0ca8urVwfMUQ==
# Mock Twilio credentials. SMSes do not work in dev environment.
- TWILIO_ACCOUNT_SID=ACmockTwilioAccountSid
- TWILIO_ACCOUNT_SID=AC00000000000000000000000000000000
- TWILIO_API_KEY=mockTwilioApiKey
- TWILIO_API_SECRET=mockTwilioApiSecret
- TWILIO_MESSAGING_SERVICE_SID=mockTwilioMsgSrvcSid
- TWILIO_MESSAGING_SERVICE_SID=MG00000000000000000000000000000000
- SP_OIDC_NDI_DISCOVERY_ENDPOINT=http://localhost:5156/singpass/v2/.well-known/openid-configuration
- SP_OIDC_NDI_JWKS_ENDPOINT=http://localhost:5156/singpass/v2/.well-known/keys
- SP_OIDC_RP_CLIENT_ID=rpClientId
Expand Down Expand Up @@ -166,6 +166,14 @@ services:
- STRIPE_API_KEY=secretKey
- STRIPE_DEVICE_NAME=StripeWebhookListener

mocktwilio:
image: stoplight/prism:4
container_name: formsg-mocktwilio
depends_on:
- backend
network_mode: 'service:backend' # reuse backend service's network stack so that it can resolve localhost:4010 to prismtwilio:4010
command: mock https://raw.githubusercontent.com/twilio/twilio-oai/main/spec/json/twilio_api_v2010.json

volumes:
mongodb_data:
driver: local
Loading

0 comments on commit cb2943a

Please sign in to comment.