Skip to content

Commit

Permalink
fix test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneleon1 committed Jul 14, 2024
1 parent a619c5c commit 880d23c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/__test__/Momo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ describe('Buyer Controller Tests', () => {
const orderRepository = dbConnection.getRepository(Order);
order = orderRepository.create({
totalAmount: 100,
country: 'RW',
status: 'Pending',
trackingNumber: '123456',
paid: false,
});

orderAmount = orderRepository.create({
totalAmount: 0,
country: 'RW',
status: 'Pending',
trackingNumber: '123456',
paid: false,
Expand Down
56 changes: 41 additions & 15 deletions src/__test__/category.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import request from 'supertest';
import app from '../app';
import { afterAllHook, beforeAllHook, getAdminToken, getVendorToken } from './testSetup';
import {
afterAllHook,
beforeAllHook,
getAdminToken,
getVendorToken,
} from './testSetup';
import { Order } from '../database/models/orderEntity';
import dbConnection from '../database';

beforeAll(beforeAllHook);
afterAll(afterAllHook);

describe('Category Creation Tests', () => {
beforeAll(async () => {
token = await getVendorToken();
adminToken = await getAdminToken()
adminToken = await getAdminToken();
});
let token: string;
let categoryId: number;
Expand All @@ -18,7 +25,7 @@ describe('Category Creation Tests', () => {
const categoryData = {
name: 'Test Category',
description: 'Test category description',
icon: 'Test category icon'
icon: 'Test category icon',
};

const response = await request(app)
Expand All @@ -39,7 +46,7 @@ describe('Category Creation Tests', () => {
it('should return a 400 status code if name is missing', async () => {
const invalidData = {
description: 'Test category description',
icon: 'Test category icon'
icon: 'Test category icon',
};

const response = await request(app)
Expand All @@ -54,7 +61,7 @@ describe('Category Creation Tests', () => {
it('should return a 400 status code if icon is missing', async () => {
const invalidData = {
description: 'Test category description',
name: 'Test category name'
name: 'Test category name',
};

const response = await request(app)
Expand Down Expand Up @@ -82,7 +89,7 @@ describe('Category Creation Tests', () => {
const existingCategoryData = {
name: 'Existing Category',
description: 'Existing category description',
icon: 'Existing category icon'
icon: 'Existing category icon',
};
await request(app)
.post('/api/v1/category')
Expand All @@ -92,7 +99,7 @@ describe('Category Creation Tests', () => {
const newCategoryData = {
name: 'Existing Category',
description: 'Existing category description',
icon: 'Existing category icon'
icon: 'Existing category icon',
};
const response = await request(app)
.post('/api/v1/category')
Expand Down Expand Up @@ -133,7 +140,7 @@ describe('Category Creation Tests', () => {
const updatedCategoryData = {
name: 'Updated Category Name',
description: 'Updated category description',
icon: 'Updated category icon'
icon: 'Updated category icon',
};

const response = await request(app)
Expand All @@ -153,7 +160,7 @@ describe('Category Creation Tests', () => {
const existingCategoryData = {
name: 'Existing Category',
description: 'Existing category description',
icon: 'Existing category icon'
icon: 'Existing category icon',
};
await request(app)
.post('/api/v1/category')
Expand All @@ -163,7 +170,7 @@ describe('Category Creation Tests', () => {
const updateCategoryData = {
name: 'Existing Category',
description: 'Existing category description',
icon: 'Existing category icon'
icon: 'Existing category icon',
};
const response = await request(app)
.put(`/api/v1/category/${categoryId}`)
Expand All @@ -181,7 +188,7 @@ describe('Category Creation Tests', () => {
.send({
name: 'Updated Category Name',
description: 'Updated category description',
icon: 'Updated category icon'
icon: 'Updated category icon',
});

expect(response.status).toBe(404);
Expand Down Expand Up @@ -209,9 +216,28 @@ describe('Category Creation Tests', () => {
it('should return an array of category metrics', async () => {
const response = await request(app)
.get('/api/v1/category/get_metrics')
.set('Authorization', `Bearer ${adminToken}`)
.set('Authorization', `Bearer ${adminToken}`);

expect(response.status).toBe(200)
expect(response.body.data).toBeDefined()
})
expect(response.status).toBe(200);
expect(response.body.data).toBeDefined();
});
it('should return an array of sales by counrty', async () => {
// Create a mock order in the database
const orderRepository = dbConnection.getRepository(Order);
const order = orderRepository.create({
totalAmount: 100,
country: 'RW',
status: 'Pending',
trackingNumber: '123456',
paid: false,
});
await orderRepository.save(order);

const response = await request(app)
.get('/api/v1/category/getSalesByCountry')
.set('Authorization', `Bearer ${adminToken}`);

expect(response.status).toBe(200);
expect(response.body.counter).toBeDefined();
});
});
2 changes: 2 additions & 0 deletions src/__test__/orderController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Order Routes', () => {
it('should update order status to Failed', async () => {
const order = orderRepository.create({
status: 'Pending',
country: 'RW',
totalAmount: 40,
trackingNumber: '34343653',
});
Expand All @@ -40,6 +41,7 @@ describe('Order Routes', () => {
const order = orderRepository.create({
status: 'Pending',
totalAmount: 40,
country: 'RW',
trackingNumber: '34343653',
});
await orderRepository.save(order);
Expand Down
1 change: 1 addition & 0 deletions src/__test__/payment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('handlePayment', () => {
order = orderRepository.create({
totalAmount: 100,
status: 'Pending',
country: 'RW',
trackingNumber: '123456',
paid: false,
});
Expand Down

0 comments on commit 880d23c

Please sign in to comment.