Skip to content

Commit

Permalink
test: etc for make coverage 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
raipen committed Nov 18, 2023
1 parent 73112e8 commit adca7e4
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/services/menuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ export default {
},
});

if (!option) option = [];

const optionMenuIds = softDeleteMenu.optionMenu
.map(({ optionId }) => optionId)
.sort();
Expand Down
108 changes: 108 additions & 0 deletions test/integration/5. etc./createWithoutParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { FastifyInstance } from 'fastify';
import { ErrorInterface } from '@DTO/index.dto';
import testValues from '../testValues';
import * as Menu from '@DTO/menu.dto';
import * as Order from '@DTO/order.dto';
import { expect, test } from '@jest/globals';

export default (app: FastifyInstance) => () => {
let tempOrderId: number;
test('order without mileage', async () => {
const response = await app.inject({
method: 'POST',
url: `/api/order`,
headers: testValues.storeHeader,
payload: {
menus: [
{
id: testValues.americanoId,
count: 1,
options: [1],
},
],
totalPrice: (2500).toString(),
},
});
expect(response.statusCode).toBe(200);
const body = JSON.parse(response.body) as Order.newOrderInterface['Reply']['200'];
expect(body.orderId).toBeDefined();
tempOrderId = body.orderId;
});

test('pay without mileage', async () => {
const response = await app.inject({
method: 'POST',
url: `/api/order/pay`,
headers: testValues.storeHeader,
payload: {
orderId: tempOrderId,
paymentMethod: 'CARD',
} as Order.payInterface['Body'],
});
expect(response.statusCode).toBe(200);
});

let tempMenuId: number;
test('register menu without option, recipe', async () => {
const response = await app.inject({
method: 'POST',
url: `/api/menu`,
headers: testValues.storeHeader,
payload: {
name: 'new menu',
price: "1000",
categoryId: testValues.coffeeCategoryId,
} as Menu.createMenuInterface['Body'],
});
expect(response.statusCode).toBe(201);
const body = JSON.parse(response.body) as Menu.createMenuInterface['Reply']['201'];
expect(body.menuId).toBeDefined();
tempMenuId = body.menuId;
});

test('update menu without option, recipe', async () => {
const response = await app.inject({
method: 'PUT',
url: `/api/menu`,
headers: testValues.storeHeader,
payload: {
id: tempMenuId,
name: 'new menu',
price: "1000",
categoryId: testValues.coffeeCategoryId,
} as Menu.updateMenuInterface['Body']
});
expect(response.statusCode).toBe(201);
const body = JSON.parse(response.body) as Menu.updateMenuInterface['Reply']['201'];
expect(body.menuId).not.toBe(tempMenuId);
});

test('update menu with recipe with unit', async () => {
const response = await app.inject({
method: 'PUT',
url: `/api/menu`,
headers: testValues.storeHeader,
payload: {
id: tempMenuId,
name: 'new menu',
price: "1000",
categoryId: testValues.coffeeCategoryId,
recipe: [
{
id: testValues.coffeeBeanId,
unit: 'g',
isMixed: false,
},
{
id: testValues.preservedLemonId,
unit: 'g',
isMixed: true,
}
],
} as Menu.updateMenuInterface['Body']
});
expect(response.statusCode).toBe(201);
const body = JSON.parse(response.body) as Menu.updateMenuInterface['Reply']['201'];
expect(body.menuId).not.toBe(tempMenuId);
});
};
13 changes: 13 additions & 0 deletions test/integration/5. etc./index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FastifyInstance } from 'fastify';
import { afterAll, describe} from '@jest/globals';
import createWithoutParams from './createWithoutParams';

const tests:[string, (app: FastifyInstance) => () => void][] = [
['create without params', createWithoutParams],
];

export default (app: FastifyInstance) => () => {
tests.forEach(([name, test]) => {
describe(name, test(app));
});
};
2 changes: 2 additions & 0 deletions test/integration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import register from './1. register';
import order from './2. order';
import update from './3. update';
import del from './4. delete';
import etc from './5. etc.';

const app: FastifyInstance = await server();

Expand All @@ -18,3 +19,4 @@ describe('register',register(app));
describe('order',order(app));
describe('update',update(app));
describe('delete',del(app));
describe('etc',etc(app));

0 comments on commit adca7e4

Please sign in to comment.