From 549a93544f5a525db3a14e2bff2564e2c2488508 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 3 Dec 2024 15:54:51 +0700 Subject: [PATCH] Create loyalty.test.js --- tests/loyalty.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/loyalty.test.js diff --git a/tests/loyalty.test.js b/tests/loyalty.test.js new file mode 100644 index 000000000..085fce342 --- /dev/null +++ b/tests/loyalty.test.js @@ -0,0 +1,25 @@ +// tests/loyalty.test.js +const Loyalty = require('../loyalty'); // Assuming you have a loyalty module + +describe('Loyalty Module', () => { + let loyalty; + + beforeEach(() => { + loyalty = new Loyalty(); + }); + + test('should add points correctly', () => { + loyalty.addPoints(100); + expect(loyalty.getPoints()).toBe(100); + }); + + test('should redeem points correctly', () => { + loyalty.addPoints(100); + loyalty.redeemPoints(50); + expect(loyalty.getPoints()).toBe(50); + }); + + test('should not allow redeeming more points than available', () => { + expect(() => loyalty.redeemPoints(50)).toThrow('Insufficient points'); + }); +});