mirror of
https://github.com/hantsy/nestjs-rest-sample.git
synced 2025-12-08 20:36:27 +00:00
chore: update deps and fixes tests
This commit is contained in:
parent
a15b351cae
commit
5ff00a1e36
@ -9,7 +9,6 @@ module.exports = {
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'prettier',
|
||||
'prettier/@typescript-eslint',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
|
||||
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "16"
|
||||
node-version: "18"
|
||||
|
||||
- name: Cache Node.js modules
|
||||
uses: actions/cache@v3
|
||||
|
||||
2
.github/workflows/dockerize.yml
vendored
2
.github/workflows/dockerize.yml
vendored
@ -17,7 +17,7 @@ jobs:
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "16"
|
||||
node-version: "18"
|
||||
|
||||
- name: Cache Node.js modules
|
||||
uses: actions/cache@v3
|
||||
|
||||
2
.github/workflows/e2e.yml
vendored
2
.github/workflows/e2e.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: "16"
|
||||
node-version: "18"
|
||||
|
||||
- name: Cache Node.js modules
|
||||
uses: actions/cache@v3
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
#npm test
|
||||
npm run lint
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# Set nginx base image
|
||||
FROM node:16
|
||||
FROM node:18
|
||||
LABEL maintainer="Hantsy Bai"
|
||||
WORKDIR /app
|
||||
COPY ./dist ./dist
|
||||
|
||||
14320
package-lock.json
generated
14320
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
76
package.json
76
package.json
@ -22,54 +22,54 @@
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
"@nestjs/config": "^2.0.0",
|
||||
"@nestjs/core": "^9.0.5",
|
||||
"@nestjs/jwt": "^10.0.1",
|
||||
"@nestjs/passport": "^9.0.0",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
"@sendgrid/mail": "^7.4.5",
|
||||
"bcrypt": "^5.0.1",
|
||||
"class-transformer": "^0.5.0",
|
||||
"@nestjs/common": "^9.4.0",
|
||||
"@nestjs/config": "^2.3.1",
|
||||
"@nestjs/core": "^9.4.0",
|
||||
"@nestjs/jwt": "^10.0.3",
|
||||
"@nestjs/passport": "^9.0.3",
|
||||
"@nestjs/platform-express": "^9.4.0",
|
||||
"@sendgrid/mail": "^7.7.0",
|
||||
"bcrypt": "^5.1.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"mongoose": "^7.0.0",
|
||||
"mongoose": "^7.0.3",
|
||||
"passport": "^0.6.0",
|
||||
"passport-jwt": "^4.0.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"passport-local": "^1.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^5.0.0",
|
||||
"rxjs": "^7.1.0"
|
||||
"rxjs": "^7.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.0.0",
|
||||
"@commitlint/config-conventional": "^17.0.0",
|
||||
"@golevelup/ts-jest": "^0.3.1",
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
"@nestjs/schematics": "^9.0.1",
|
||||
"@nestjs/testing": "^8.0.0",
|
||||
"@commitlint/cli": "^17.6.1",
|
||||
"@commitlint/config-conventional": "^17.6.1",
|
||||
"@golevelup/ts-jest": "^0.3.5",
|
||||
"@nestjs/cli": "^9.4.0",
|
||||
"@nestjs/schematics": "^9.1.0",
|
||||
"@nestjs/testing": "^9.4.0",
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "^27.0.1",
|
||||
"@types/node": "^18.0.0",
|
||||
"@types/passport-jwt": "^3.0.6",
|
||||
"@types/passport-local": "^1.0.34",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "5.57.1",
|
||||
"@typescript-eslint/parser": "5.57.1",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/passport-jwt": "^3.0.8",
|
||||
"@types/passport-local": "^1.0.35",
|
||||
"@types/supertest": "^2.0.12",
|
||||
"@typescript-eslint/eslint-plugin": "5.58.0",
|
||||
"@typescript-eslint/parser": "5.58.0",
|
||||
"eslint": "8.38.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
"husky": "^8.0.1",
|
||||
"jest": "^27.0.6",
|
||||
"jest-mock-extended": "^3.0.1",
|
||||
"prettier": "^2.3.2",
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "^27.0.3",
|
||||
"ts-loader": "^9.2.3",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^29.5.0",
|
||||
"jest-mock-extended": "^3.0.4",
|
||||
"prettier": "^2.8.7",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-loader": "^9.4.2",
|
||||
"ts-mockito": "^2.6.1",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsconfig-paths": "^4.0.0",
|
||||
"typescript": "^4.3.5"
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { REQUEST } from '@nestjs/core';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { FilterQuery, Model } from 'mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
import { Comment } from '../database/comment.model';
|
||||
import { COMMENT_MODEL, POST_MODEL } from '../database/database.constants';
|
||||
import { Post } from '../database/post.model';
|
||||
@ -99,22 +100,15 @@ describe('PostService', () => {
|
||||
expect(data.length).toBe(3);
|
||||
expect(model.find).toHaveBeenCalled();
|
||||
|
||||
jest
|
||||
.spyOn(model, 'find')
|
||||
.mockImplementation(
|
||||
(
|
||||
conditions: FilterQuery<Post>,
|
||||
callback?: (err: any, res: Post[]) => void,
|
||||
) => {
|
||||
return {
|
||||
skip: jest.fn().mockReturnValue({
|
||||
limit: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValueOnce([posts[0]]),
|
||||
}),
|
||||
}),
|
||||
} as any;
|
||||
},
|
||||
);
|
||||
jest.spyOn(model, 'find').mockImplementation(() => {
|
||||
return {
|
||||
skip: jest.fn().mockReturnValue({
|
||||
limit: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValueOnce([posts[0]]),
|
||||
}),
|
||||
}),
|
||||
} as any;
|
||||
});
|
||||
|
||||
const result = await lastValueFrom(service.findAll('Generate', 0, 10));
|
||||
expect(result.length).toBe(1);
|
||||
@ -171,14 +165,14 @@ describe('PostService', () => {
|
||||
const toReturned = {
|
||||
_id: '5ee49c3115a4e75254bb732e',
|
||||
...toCreated,
|
||||
} as Post;
|
||||
} as any;
|
||||
|
||||
jest
|
||||
.spyOn(model, 'create')
|
||||
.mockImplementation(() => Promise.resolve(toReturned));
|
||||
.mockImplementation(() => Promise.resolve([toReturned]));
|
||||
|
||||
const data = await lastValueFrom(service.save(toCreated));
|
||||
expect(data._id).toBe('5ee49c3115a4e75254bb732e');
|
||||
expect(data[0]._id).toBe('5ee49c3115a4e75254bb732e');
|
||||
expect(model.create).toBeCalledWith({
|
||||
...toCreated,
|
||||
createdBy: {
|
||||
@ -300,26 +294,19 @@ describe('PostService', () => {
|
||||
});
|
||||
|
||||
it('should get comments of post ', async () => {
|
||||
jest
|
||||
.spyOn(commentModel, 'find')
|
||||
.mockImplementation(
|
||||
(
|
||||
conditions: FilterQuery<Comment>,
|
||||
callback?: (err: any, res: Comment[]) => void,
|
||||
) => {
|
||||
return {
|
||||
select: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValue([
|
||||
{
|
||||
_id: 'test',
|
||||
content: 'content',
|
||||
post: { _id: '_test_id' },
|
||||
},
|
||||
] as any),
|
||||
}),
|
||||
} as any;
|
||||
},
|
||||
);
|
||||
jest.spyOn(commentModel, 'find').mockImplementation(() => {
|
||||
return {
|
||||
select: jest.fn().mockReturnValue({
|
||||
exec: jest.fn().mockResolvedValue([
|
||||
{
|
||||
_id: 'test',
|
||||
content: 'content',
|
||||
post: { _id: '_test_id' },
|
||||
},
|
||||
] as any),
|
||||
}),
|
||||
} as any;
|
||||
});
|
||||
|
||||
const result = await lastValueFrom(service.commentsOf('test'));
|
||||
expect(result.length).toBe(1);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { Model } from 'mongoose';
|
||||
import { Model, FilterQuery } from 'mongoose';
|
||||
import { lastValueFrom, of } from 'rxjs';
|
||||
|
||||
import { USER_MODEL } from '../database/database.constants';
|
||||
@ -91,16 +91,15 @@ describe('UserService', () => {
|
||||
});
|
||||
|
||||
it('findByUsername should return user', async () => {
|
||||
jest
|
||||
.spyOn(model, 'findOne')
|
||||
.mockImplementation((filter: any, callback: any) => {
|
||||
return {
|
||||
jest.spyOn(model, 'findOne').mockImplementation(
|
||||
(filter?: FilterQuery<User>) =>
|
||||
({
|
||||
exec: jest.fn().mockResolvedValue({
|
||||
username: 'hantsy',
|
||||
email: 'hantsy@example.com',
|
||||
} as User),
|
||||
} as any;
|
||||
});
|
||||
} as any),
|
||||
);
|
||||
|
||||
const foundUser = await lastValueFrom(service.findByUsername('hantsy'));
|
||||
expect(foundUser).toEqual({
|
||||
@ -113,18 +112,16 @@ describe('UserService', () => {
|
||||
|
||||
describe('findById', () => {
|
||||
it('return one result', async () => {
|
||||
jest
|
||||
.spyOn(model, 'findOne')
|
||||
.mockImplementation(
|
||||
(filter: any, callback: any) => {
|
||||
return {
|
||||
exec: jest.fn().mockResolvedValue({
|
||||
username: 'hantsy',
|
||||
email: 'hantsy@example.com',
|
||||
} as User),
|
||||
} as any;
|
||||
},
|
||||
);
|
||||
jest.spyOn(model, 'findOne')
|
||||
.mockImplementation(
|
||||
(filter?: FilterQuery<User>) =>
|
||||
({
|
||||
exec: jest.fn().mockResolvedValue({
|
||||
username: 'hantsy',
|
||||
email: 'hantsy@example.com',
|
||||
} as User),
|
||||
} as any),
|
||||
);
|
||||
|
||||
const foundUser = await lastValueFrom(service.findById('hantsy'));
|
||||
expect(foundUser).toEqual({
|
||||
@ -138,13 +135,9 @@ describe('UserService', () => {
|
||||
it('return a null result', async () => {
|
||||
jest
|
||||
.spyOn(model, 'findOne')
|
||||
.mockImplementation(
|
||||
(filter: any, callback: any) => {
|
||||
return {
|
||||
exec: jest.fn().mockResolvedValue(null) as any,
|
||||
} as any;
|
||||
},
|
||||
);
|
||||
.mockImplementation((filter?: FilterQuery<User>) => ({
|
||||
exec: jest.fn().mockResolvedValue(null) as any,
|
||||
} as any));
|
||||
|
||||
try {
|
||||
const foundUser = await lastValueFrom(service.findById('hantsy'));
|
||||
@ -156,17 +149,13 @@ describe('UserService', () => {
|
||||
it('parameter withPosts=true', async () => {
|
||||
jest
|
||||
.spyOn(model, 'findOne')
|
||||
.mockImplementation(
|
||||
(filter: any, callback: any) => {
|
||||
return {
|
||||
populate: jest.fn().mockReturnThis(),
|
||||
exec: jest.fn().mockResolvedValue({
|
||||
username: 'hantsy',
|
||||
email: 'hantsy@example.com',
|
||||
} as User),
|
||||
} as any;
|
||||
},
|
||||
);
|
||||
.mockImplementation((filter?: FilterQuery<User>) => ({
|
||||
populate: jest.fn().mockReturnThis(),
|
||||
exec: jest.fn().mockResolvedValue({
|
||||
username: 'hantsy',
|
||||
email: 'hantsy@example.com',
|
||||
} as User),
|
||||
} as any));
|
||||
|
||||
const foundUser = await lastValueFrom(service.findById('hantsy', true));
|
||||
expect(foundUser).toEqual({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user