Skip to content

Commit

Permalink
test: add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
bs32g1038 committed Jul 28, 2023
1 parent 7ad53d8 commit 90bab67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/e2e/article.module.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { getToken } from '../util';
import { Connection, Model } from 'mongoose';
import { Article } from '@blog/server/models/article.model';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { Draft } from '@blog/server/models/draft.model';

const __TOKEN__ = getToken();

/**
Expand All @@ -17,6 +19,7 @@ describe('article.module.e2e', () => {
let mongod: MongoMemoryServer;
let mongooseConnection: Connection;
let articleModel: Model<Article>;
let draftModel: Model<Draft>;

beforeAll(async () => {
const instance = await initApp({
Expand All @@ -26,6 +29,7 @@ describe('article.module.e2e', () => {
mongod = instance.mongod;
mongooseConnection = instance.mongooseConnection;
articleModel = instance.articleModel;
draftModel = instance.draftModel;
});

beforeEach(async () => {
Expand Down Expand Up @@ -88,13 +92,15 @@ describe('article.module.e2e', () => {
.expect(400);
});

test('bad request, update the article data & the data not found in db', async () => {
test('should success!, update the article data & the data not found in db and the data is in draft box', async () => {
const draft = { data: {}, type: 'article' };
const { _id } = await draftModel.create(draft);
const article = getArticle();
return request(app.getHttpServer())
.put('/api/articles/' + getObjectId())
.put('/api/articles/' + _id)
.set('authorization', __TOKEN__)
.send(article)
.expect(400);
.expect(200);
});
});

Expand Down
17 changes: 17 additions & 0 deletions test/e2e/draft.module.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getToken } from '../util';
import { Connection, Model } from 'mongoose';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { Draft } from '@blog/server/models/draft.model';
import { getObjectId } from '../faker';
const __TOKEN__ = getToken();

/**
Expand Down Expand Up @@ -64,6 +65,15 @@ describe('draft.module.e2e', () => {
.send(draft)
.expect(200);
});

test('if not found the draft, it create draft should success', async () => {
const draft = { data: {}, type: 'article' };
return request(app.getHttpServer())
.put('/api/drafts/' + getObjectId())
.set('authorization', __TOKEN__)
.send(draft)
.expect(200);
});
});

describe('get one draft', () => {
Expand All @@ -79,6 +89,13 @@ describe('draft.module.e2e', () => {
expect(a.data).toEqual(draft.data);
});
});

test('get draft not found', async () => {
return request(app.getHttpServer())
.get('/api/drafts/' + getObjectId())
.set('authorization', __TOKEN__)
.expect(404);
});
});

describe('get draft list', () => {
Expand Down

0 comments on commit 90bab67

Please sign in to comment.