Skip to content

Commit

Permalink
Add tests for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Vylpes committed Feb 13, 2024
1 parent f5dab28 commit c2bbb31
Show file tree
Hide file tree
Showing 46 changed files with 5,748 additions and 604 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/constants/DefaultSettings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TOOD: This should be a map
export const DefaultSettings = Object({
"return.count": "1"
});
2 changes: 1 addition & 1 deletion src/constants/Status/SupplyPurchaseStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const SupplyPurchaseStatusNames = new Map<SupplyPurchaseStatus, string>([
[ SupplyPurchaseStatus.Received, "Received" ],
[ SupplyPurchaseStatus.Inventoried, "Inventoried" ],
[ SupplyPurchaseStatus.Complete, "Complete" ],
[ SupplyPurchaseStatus.Received, "Rejected" ],
[ SupplyPurchaseStatus.Rejected, "Rejected" ],
]);
7 changes: 3 additions & 4 deletions src/helpers/Validation/Body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export default class Body {
}
break;
case ValidationRule.Number:
console.log(typeof Number(0));
if (typeof Number(req.body[rule.field]) != "number") {
if (!Number(req.body[rule.field])) {
await message.Error(rule.errorMessage || `${rule.field} must be a number`);

if (!this.onFail) {
Expand Down Expand Up @@ -164,7 +163,7 @@ export default class Body {
}
break;
case ValidationRule.GreaterThan:
if (Number(req.body[rule.field]) <= rule.length) {
if (!Number(req.body[rule.field]) || Number(req.body[rule.field]) <= rule.length) {
await message.Error(rule.errorMessage || `${rule.field} must be greater than ${rule.length}`);

if (!this.onFail) {
Expand All @@ -177,7 +176,7 @@ export default class Body {
}
break;
case ValidationRule.LessThan:
if (Number(req.body[rule.field]) >= rule.length) {
if (!Number(req.body[rule.field]) || Number(req.body[rule.field]) >= rule.length) {
await message.Error(rule.errorMessage || `${rule.field} must be less than ${rule.length}`);

if (!this.onFail) {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/userMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class UserMiddleware {
if (req.session.User) {
next();
} else {
req.session.error = "Access denied";
req.flash('error', 'Access denied');
res.redirect('/auth/login');
}
}
Expand Down
6 changes: 5 additions & 1 deletion tests/constants/DefaultSettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { DefaultSettings } from '../../src/constants/DefaultSettings';

describe('DefaultSettings', () => {
test.todo("GIVEN input is return.count, EXPECT 1 to be returned");
test("GIVEN input is return.count, EXPECT 1 to be returned", () => {
expect(DefaultSettings["return.count"]).toBe("1");
});
});
5 changes: 0 additions & 5 deletions tests/constants/PostageService.test.ts

This file was deleted.

11 changes: 11 additions & 0 deletions tests/constants/PostalService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PostalService, PostalServiceNames } from '../../src/constants/PostalService';

describe('PostalServiceNames', () => {
test('GIVEN input is RoyalMail, EXPECT Royal Mail string returned', () => {
expect(PostalServiceNames.get(PostalService.RoyalMail)).toBe("Royal Mail");
});

test('GIVEN input is Hermes, EXPECT Hermes string returned', () => {
expect(PostalServiceNames.get(PostalService.Hermes)).toBe("Hermes");
});
});
22 changes: 17 additions & 5 deletions tests/constants/Status/ItemPurchaseStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { ItemPurchaseStatus, ItemPurchaseStatusNames } from '../../../src/constants/Status/ItemPurchaseStatus';

describe('ItemPurchaseStatusNames', () => {
test.todo('GIVEN input is Ordered, EXPECT Ordered string returned');
test('GIVEN input is Ordered, EXPECT Ordered string returned', () => {
expect(ItemPurchaseStatusNames.get(ItemPurchaseStatus.Ordered)).toBe("Ordered");
});

test.todo('GIVEN input is Received, EXPECT Received string returned');
test('GIVEN input is Received, EXPECT Received string returned', () => {
expect(ItemPurchaseStatusNames.get(ItemPurchaseStatus.Received)).toBe("Received");
});

test.todo('GIVEN input is Inventoried, EXPECT Inventoried string returned');
test('GIVEN input is Inventoried, EXPECT Inventoried string returned', () => {
expect(ItemPurchaseStatusNames.get(ItemPurchaseStatus.Inventoried)).toBe("Inventoried");
});

test.todo('GIVEN input is Complete, EXPECT Complete string returned');
test('GIVEN input is Complete, EXPECT Complete string returned', () => {
expect(ItemPurchaseStatusNames.get(ItemPurchaseStatus.Complete)).toBe("Complete");
});

test.todo('GIVEN input is Rejected, EXPECT Rejected string returned');
test('GIVEN input is Rejected, EXPECT Rejected string returned', () => {
expect(ItemPurchaseStatusNames.get(ItemPurchaseStatus.Rejected)).toBe("Rejected");
});
});
18 changes: 14 additions & 4 deletions tests/constants/Status/ItemStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { ItemStatus, ItemStatusNames } from '../../../src/constants/Status/ItemStatus';

describe('ItemStatusNames', () => {
test.todo('GIVEN input is Unlisted, EXPECT Unlisted string returned');
test('GIVEN input is Unlisted, EXPECT Unlisted string returned', () => {
expect(ItemStatusNames.get(ItemStatus.Unlisted)).toBe("Unlisted");
});

test.todo('GIVEN input is Listed, EXPECT Listed string returned');
test('GIVEN input is Listed, EXPECT Listed string returned', () => {
expect(ItemStatusNames.get(ItemStatus.Listed)).toBe("Listed");
});

test.todo('GIVEN input is Sold, EXPECT Sold string returned');
test('GIVEN input is Sold, EXPECT Sold string returned', () => {
expect(ItemStatusNames.get(ItemStatus.Sold)).toBe("Sold");
});

test.todo('GIVEN input is Rejected, EXPECT Rejected string returned');
test('GIVEN input is Rejected, EXPECT Rejected string returned', () => {
expect(ItemStatusNames.get(ItemStatus.Rejected)).toBe("Rejected");
});
});
14 changes: 11 additions & 3 deletions tests/constants/Status/ListingStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { ListingStatus, ListingStatusNames } from '../../../src/constants/Status/ListingStatus';

describe('ListingStatusNames', () => {
test.todo('GIVEN input is Active, EXPECT Active string returned');
test('GIVEN input is Active, EXPECT Active string returned', () => {
expect(ListingStatusNames.get(ListingStatus.Active)).toBe("Active");
});

test.todo('GIVEN input is Sold, EXPECT Sold string returned');
test('GIVEN input is Sold, EXPECT Sold string returned', () => {
expect(ListingStatusNames.get(ListingStatus.Sold)).toBe("Sold");
});

test.todo('GIVEN string is Unsold, EXPECT Unsold string returned');
test('GIVEN input is Unsold, EXPECT Unsold string returned', () => {
expect(ListingStatusNames.get(ListingStatus.Unsold)).toBe("Unsold");
});
});
22 changes: 17 additions & 5 deletions tests/constants/Status/OrderStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { OrderStatus, OrderStatusNames } from '../../../src/constants/Status/OrderStatus';

describe('OrderStatusNames', () => {
test.todo('GIVEN input is AwaitingPayment, EXPECT Awaiting Payment string returned');
test('GIVEN input is AwaitingPayment, EXPECT Awaiting Payment string returned', () => {
expect(OrderStatusNames.get(OrderStatus.AwaitingPayment)).toBe("Awaiting Payment");
});

test.todo('GIVEN input is AwaitingDispatch, EXPECT Awaiting Dispatch string returned');
test('GIVEN input is AwaitingDispatch, EXPECT Awaiting Dispatch string returned', () => {
expect(OrderStatusNames.get(OrderStatus.AwaitingDispatch)).toBe("Awaiting Dispatch");
});

test.todo('GIVEN input is Dispatched, EXPECT Dispatched string returned');
test('GIVEN input is Dispatched, EXPECT Dispatched string returned', () => {
expect(OrderStatusNames.get(OrderStatus.Dispatched)).toBe("Dispatched");
});

test.todo('GIVEN input is Cancelled, EXPECT Cancelled string returned');
test('GIVEN input is Cancelled, EXPECT Cancelled string returned', () => {
expect(OrderStatusNames.get(OrderStatus.Cancelled)).toBe("Cancelled");
});

test.todo('GIVEN input is Returned, EXPECT Returned string returned');
test('GIVEN input is Returned, EXPECT Returned string returned', () => {
expect(OrderStatusNames.get(OrderStatus.Returned)).toBe("Returned");
});
});
26 changes: 20 additions & 6 deletions tests/constants/Status/ReturnStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { ReturnStatus, ReturnStatusNames } from '../../../src/constants/Status/ReturnStatus';

describe('ReturnStatusNames', () => {
test.todo('GIVEN input is Opened, EXPECT Opened string returned');
test('GIVEN input is Opened, EXPECT Opened string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.Opened)).toBe("Opened");
});

test.todo('GIVEN input is Started, EXPECT Started string returned');
test('GIVEN input is Started, EXPECT Started string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.Started)).toBe("Started");
});

test.todo('GIVEN input is ItemPosted, EXPECT Item Posted string returned');
test('GIVEN input is ItemPosted, EXPECT Item Posted string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.ItemPosted)).toBe("Item Posted");
});

test.todo('GIVEN input is ItemReceived, EXPECT Item Received string returned');
test('GIVEN input is ItemReceived, EXPECT Item Received string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.ItemReceived)).toBe("Item Received");
});

test.todo('GIVEN input is Refunded, EXPECT Refunded string returned');
test('GIVEN input is Refunded, EXPECT Refunded string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.Refunded)).toBe("Refunded");
});

test.todo('GIVEN input is Closed, EXPECT Closed string returned');
test('GIVEN input is Closed, EXPECT Closed string returned', () => {
expect(ReturnStatusNames.get(ReturnStatus.Closed)).toBe("Closed");
});
});
22 changes: 17 additions & 5 deletions tests/constants/Status/SupplyPurchaseStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { SupplyPurchaseStatus, SupplyPurchaseStatusNames } from '../../../src/constants/Status/SupplyPurchaseStatus';

describe('SupplyPurchaseStatusNames', () => {
test.todo('GIVEN input is Ordered, EXPECT Ordered string returned');
test('GIVEN input is Ordered, EXPECT Ordered string returned', () => {
expect(SupplyPurchaseStatusNames.get(SupplyPurchaseStatus.Ordered)).toBe("Ordered");
});

test.todo('GIVEN input is Received, EXPECT Received string returned');
test('GIVEN input is Received, EXPECT Received string returned', () => {
expect(SupplyPurchaseStatusNames.get(SupplyPurchaseStatus.Received)).toBe("Received");
});

test.todo('GIVEN input is Inventoried, EXPECT Inventoried string returned');
test('GIVEN input is Inventoried, EXPECT Inventoried string returned', () => {
expect(SupplyPurchaseStatusNames.get(SupplyPurchaseStatus.Inventoried)).toBe("Inventoried");
});

test.todo('GIVEN input is Complete, EXPECT Complete string returned');
test('GIVEN input is Complete, EXPECT Complete string returned', () => {
expect(SupplyPurchaseStatusNames.get(SupplyPurchaseStatus.Complete)).toBe("Complete");
});

test.todo('GIVEN input is Rejected, EXPECT Rejected string returned');
test('GIVEN input is Rejected, EXPECT Rejected string returned', () => {
expect(SupplyPurchaseStatusNames.get(SupplyPurchaseStatus.Rejected)).toBe("Rejected");
});
});
10 changes: 8 additions & 2 deletions tests/constants/Status/SupplyStatus.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { SupplyStatus, SupplyStatusNames } from '../../../src/constants/Status/SupplyStatus';

describe('SupplyStatusNames', () => {
test.todo('GIVEN input is Unused, EXPECT Unused string returned');
test('GIVEN input is Unused, EXPECT Unused string returned', () => {
expect(SupplyStatusNames.get(SupplyStatus.Unused)).toBe("Unused");
});

test.todo('GIVEN input is Used, EXPECT Used string returned');
test('GIVEN input is Used, EXPECT Used string returned', () => {
expect(SupplyStatusNames.get(SupplyStatus.Used)).toBe("Used");
});
});
14 changes: 11 additions & 3 deletions tests/constants/StorageType.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { StorageType, StorageTypeNames } from '../../src/constants/StorageType';

describe('StorageTypeNames', () => {
test.todo("GIVEN input is Bin, EXPECT Bin string returned");
test("GIVEN input is Bin, EXPECT Bin string returned", () => {
expect(StorageTypeNames.get(StorageType.Bin)).toBe("Bin");
});

test.todo("GIVEN input is Unit, EXPECT Unit string returned");
test("GIVEN input is Unit, EXPECT Unit string returned", () => {
expect(StorageTypeNames.get(StorageType.Unit)).toBe("Unit");
});

test.todo("GIVEN input is Building, EXPECT Building string returned");
test("GIVEN input is Building, EXPECT Building string returned", () => {
expect(StorageTypeNames.get(StorageType.Building)).toBe("Building");
});
});
Loading

0 comments on commit c2bbb31

Please sign in to comment.