Skip to content

Commit

Permalink
Feature/im test env init (#129)
Browse files Browse the repository at this point in the history
These updates allow for us to use the npm run deploy:test to deploy both
the api and the ui to the test envrionment. I also updated the emailing
and other services to treat test like prod and allow for notifications
to be sent.

---------
  • Loading branch information
QuinnNTonic committed Oct 26, 2023
1 parent 49530e8 commit 0d59a77
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
5 changes: 4 additions & 1 deletion app.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
runtime: nodejs14
runtime: nodejs16

instance_class: F4

build_env_variables:
GOOGLE_NODE_RUN_SCRIPTS: ''
2 changes: 1 addition & 1 deletion apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function bootstrap() {

// app.useWebSocketAdapter(new IoAdapter(app));

if (environment.production) {
if (environment.production || environment.test) {
const port = Number(process.env.PORT) || 8080;
await app.listen(port);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class UserSessionEffects {
this.user.signUp({ token: true }, dto).pipe(
map(({ token }) => {
ImAuthTokenStorage.setValue({ id: dto.id, token });
if (environment.production) {
if (environment.production || environment.test) {
(async () => {
const modal = await this.infoModal.open({
title: 'Check your email',
Expand Down
2 changes: 1 addition & 1 deletion libs/client/shared/data-access/src/lib/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AuthInterceptor implements OrchaInterceptor {
next
.handle(authReq)
// Simulate HTTP delay for development.
.pipe(environment.production ? tap() : delay(Math.floor(Math.random() * (400 - 50 + 1) + 50)))
.pipe(environment.production || environment.test ? tap() : delay(Math.floor(Math.random() * (400 - 50 + 1) + 50)))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class AuthService {
}

const user = await this.userRepo.findOneOrFail(sign.userId);
if (!user.active && environment.production) {
if (!user.active && (environment.production || environment.test)) {
throw new HttpException(`Email "${user.id}" has not been verified.`, HttpStatus.UNAUTHORIZED);
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export class AuthService {
throw new HttpException(`You do not own this profile.`, HttpStatus.UNAUTHORIZED);
}

if (!user.active && environment.production) {
if (!user.active && (environment.production || environment.test)) {
throw new HttpException(`Your email has not been verified.`, HttpStatus.UNAUTHORIZED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import * as mailgun from 'mailgun-js';

@Injectable()
export class EmailService {
mg = environment.production ? mailgun.default(environment.mailgun) : null;
mg = environment.production || environment.test ? mailgun.default(environment.mailgun) : null;
noreply = 'your no reply <noreply@example.com>';

shouldNotSendNotification = !environment.production && !environment.test;

constructor(@Inject(FRONTEND_ROUTES_TOKEN) private readonly route: FrontendRoutes) { }

sendInfoEmail({
Expand All @@ -20,7 +22,7 @@ export class EmailService {
subject: string;
email: string | string[];
}) {
if (!environment.production) return;
if (this.shouldNotSendNotification) return;

const msg = {
from: this.noreply,
Expand All @@ -35,7 +37,7 @@ export class EmailService {
}

sendEmailVerification(email: string, hash: string, registerAs?: SignUpDto['registerAs']) {
if (!environment.production) return;
if (this.shouldNotSendNotification) return;

const url = `${environment.appUrl}${this.route.path.verifyEmail.ROOT}?email=${email}&hash=${hash}&register=${registerAs}`;

Expand All @@ -52,7 +54,7 @@ export class EmailService {
}

sendForgotPassword(email: string, hash: string) {
if (!environment.production) return;
if (this.shouldNotSendNotification) return;

const url = `${environment.appUrl}${this.route.path.forgotPasswordChange.ROOT}?email=${email}&hash=${hash}`;

Expand All @@ -77,7 +79,7 @@ export class EmailService {
temporaryPassword: string,
forgotPasswordHash: string
) {
if (!environment.production) return;
if (this.shouldNotSendNotification) return;

const url = `${environment.appUrl}${this.route.path.activateUserAccount.ROOT}?email=${newUserEmail}&epId=${newEpId}&activationHash=${activationHash}&temporaryPassword=${temporaryPassword}&forgotPasswordHash=${forgotPasswordHash}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const sendingPhone = environment.twilio.sendingPhone;

@Injectable()
export class SMSService {
private t = environment.production ? twilio.default(accountSid, authToken) : null;
private t = environment.production || environment.test ? twilio.default(accountSid, authToken) : null;

shouldNotSendNotification = (!environment.production && !environment.test);

sendInfoSMS({ message, phone }: { message: string; phone: string }) {
if (!environment.production || !phone || !message) return;
if (this.shouldNotSendNotification || !phone || !message) return;

return this.t?.messages.create({
body: `involveMINT notification: ${message}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class UserService {
if (!compare) {
throw new HttpException(`Incorrect password.`, HttpStatus.UNAUTHORIZED);
}
if (!user.active && environment.production) {
if (!user.active && (environment.production || environment.test)) {
throw new HttpException(`User ${user.id} has not been verified.`, HttpStatus.UNAUTHORIZED);
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"deploy:server": "nx run-many --target=build --projects=api --prod --skip-nx-cache && gcloud config set project involvemint2 && gcloud app deploy app.yaml --stop-previous-version --quiet",
"deploy:client": "nx run-many --target=build --projects=involvemint --prod --skip-nx-cache && firebase use involvemint2 && firebase deploy",
"deploy": "nx run-many --target=build --projects=involvemint,api --prod --skip-nx-cache && gcloud config set project involvemint2 && gcloud app deploy app.yaml --stop-previous-version --quiet && firebase use involvemint2 && firebase deploy && gcloud config set project involvemint-test && gcloud app deploy app.yaml --stop-previous-version --quiet && firebase use involvemint-test && firebase deploy",
"deploy:test": "nx run-many --target=build --projects=involvemint,api --configuration=test --skip-nx-cache && gcloud config set project involvemint-test && gcloud app deploy app.yaml --stop-previous-version --quiet && firebase use involvemint-test && firebase deploy",
"deploy:test:server": "nx run-many --target=build --projects=api --configuration=test --skip-nx-cache && gcloud config set project involvemint-test && gcloud app deploy app.yaml --stop-previous-version --quiet",
"deploy:test:client": "nx run-many --target=build --projects=involvemint --configuration=test --skip-nx-cache && firebase use involvemint-test && firebase deploy",
"deploy:test": "nx run-many --target=build --projects=involvemint,api --configuration=test --skip-nx-cache && gcloud config set project im-test-395400 && gcloud app deploy app.yaml --stop-previous-version --quiet && firebase use im-test-395400 && firebase deploy",
"deploy:test:server": "nx run-many --target=build --projects=api --configuration=test --skip-nx-cache && gcloud config set project im-test-395400 && gcloud app deploy app.yaml --stop-previous-version --quiet",
"deploy:test:client": "nx run-many --target=build --projects=involvemint --configuration=test --skip-nx-cache && firebase use im-test-395400 && firebase deploy",
"test": "nx run-many --target=test --all",
"lint": "nx run-many --target=lint --all",
"e2e": "ng e2e",
Expand Down

0 comments on commit 0d59a77

Please sign in to comment.