Skip to content

Commit fe4fae7

Browse files
authored
Merge pull request #43 from hwgilbert16/develop
v1.0.6 Release
2 parents 3fbca09 + 3c428bc commit fe4fae7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+999
-278
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"max-len": "off",
4747
"require-jsdoc": "off",
4848
"camelcase": ["error", { "allow": ["jwt_decode"] }],
49-
"valid-jsdoc": "off"
49+
"valid-jsdoc": "off",
50+
"linebreak-style": ["error", "unix"]
5051
}
5152
},
5253
{

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
node-version: 'lts/Hydrogen'
1616

17-
- name: Install dependencies and run migrations
17+
- name: Install dependencies and generate Prisma types
1818
run: |
1919
npm install --legacy-peer-deps
2020
npm run generate

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212
with:
1313
node-version: 'lts/Hydrogen'
1414

15-
- name: Install dependencies and run migrations
15+
- name: Install dependencies and generate Prisma types
1616
run: |
1717
npm install --legacy-peer-deps
1818
npm run generate
1919
20-
- name: Build website and lint
20+
- name: Build and lint
2121
run: |
2222
npm run build
2323
npm run lint
2424
2525
- name: Run tests
26-
run: npx nx test api
26+
run: npm run test
2727

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# syntax=docker/dockerfile:1.3-labs
2-
FROM node:18
2+
FROM node:lts-alpine3.18
33

44
ARG NODE_ENV
55
ARG DATABASE_PASSWORD

apps/api/src/app/auth/auth.controller.spec.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
1111
import { MailService } from "../providers/mail/mail.service";
1212
import { Request, Response } from "express";
1313
import { HttpException } from "@nestjs/common";
14+
import { ApiResponseOptions } from "@scholarsome/shared";
1415

1516
describe("AuthController", () => {
1617
let authController: AuthController;
@@ -73,6 +74,7 @@ describe("AuthController", () => {
7374

7475
return {};
7576
},
77+
setLoginCookies: jest.fn(),
7678
validateRecaptcha: (s: string) => {
7779
switch (s) {
7880
case "true":
@@ -168,7 +170,7 @@ describe("AuthController", () => {
168170

169171
expect(res.status).toHaveBeenCalledWith(401);
170172
expect(result).toEqual({
171-
status: "fail",
173+
status: ApiResponseOptions.Fail,
172174
message: "Invalid reset token"
173175
});
174176
});
@@ -185,7 +187,7 @@ describe("AuthController", () => {
185187
}
186188
});
187189
expect(result).toEqual({
188-
status: "success",
190+
status: ApiResponseOptions.Success,
189191
data: {}
190192
});
191193
});
@@ -238,7 +240,7 @@ describe("AuthController", () => {
238240
const result = await authController.sendReset({ email: "true" });
239241

240242
expect(result).toEqual({
241-
status: "success",
243+
status: ApiResponseOptions.Success,
242244
data: null
243245
});
244246
});
@@ -277,7 +279,7 @@ describe("AuthController", () => {
277279
const result = await authController.verifyEmail({ token: "" }, res);
278280

279281
expect(result).toEqual({
280-
status: "fail",
282+
status: ApiResponseOptions.Fail,
281283
message: "Invalid token"
282284
});
283285
});
@@ -291,6 +293,23 @@ describe("AuthController", () => {
291293
// eslint-disable-next-line @typescript-eslint/no-explicit-any
292294
} as any as Response;
293295

296+
it("should return a normal response body", async () => {
297+
const dto = {
298+
username: "false",
299+
email: "false",
300+
password: "b",
301+
confirmPassword: "b",
302+
recaptchaToken: "a"
303+
};
304+
305+
const result = await authController.register(dto, res);
306+
307+
expect(result).toEqual({
308+
status: ApiResponseOptions.Success,
309+
data: null
310+
});
311+
});
312+
294313
it("should send HTTP 409 if user already exists", async () => {
295314
const dto = {
296315
username: "true",
@@ -304,7 +323,7 @@ describe("AuthController", () => {
304323

305324
expect(res.status).toHaveBeenCalledWith(409);
306325
expect(result).toEqual({
307-
status: "fail",
326+
status: ApiResponseOptions.Fail,
308327
message: "Email already exists"
309328
});
310329
});
@@ -328,7 +347,7 @@ describe("AuthController", () => {
328347
});
329348
});
330349

331-
it("should not send email if email not enabled", async () => {
350+
it("should set login cookies", async () => {
332351
const dto = {
333352
username: "false",
334353
email: "false",
@@ -337,13 +356,9 @@ describe("AuthController", () => {
337356
recaptchaToken: "a"
338357
};
339358

340-
const result = await authController.register(dto, res);
359+
await authController.register(dto, res);
341360

342-
expect(mailService.sendEmailConfirmation).toHaveBeenCalledWith(dto.email);
343-
expect(result).toEqual({
344-
status: "success",
345-
data: { confirmEmail: false }
346-
});
361+
expect(authService.setLoginCookies).toHaveBeenCalled();
347362
});
348363
});
349364

@@ -366,7 +381,7 @@ describe("AuthController", () => {
366381

367382
expect(res.status).toHaveBeenCalledWith(401);
368383
expect(result).toEqual({
369-
status: "fail",
384+
status: ApiResponseOptions.Fail,
370385
message: "Incorrect email or password"
371386
});
372387
});
@@ -420,22 +435,7 @@ describe("AuthController", () => {
420435

421436
await authController.login(dto, res);
422437

423-
expect(res.cookie).toHaveBeenNthCalledWith(1, "verified", "", {
424-
httpOnly: false,
425-
expires: expect.any(Date)
426-
});
427-
expect(res.cookie).toHaveBeenNthCalledWith(2, "refresh_token", {}, {
428-
httpOnly: true,
429-
expires: expect.any(Date)
430-
});
431-
expect(res.cookie).toHaveBeenNthCalledWith(3, "access_token", {}, {
432-
httpOnly: true,
433-
expires: expect.any(Date)
434-
});
435-
expect(res.cookie).toHaveBeenNthCalledWith(4, "authenticated", true, {
436-
httpOnly: false,
437-
expires: expect.any(Date)
438-
});
438+
expect(authService.setLoginCookies).toHaveBeenCalled();
439439
});
440440
});
441441

0 commit comments

Comments
 (0)