Raw
1 import { isGiftCardExpired } from "../gift-card";
2
3 describe("isGiftCardExpired", () => {
4 it("returns false when the gift card has no expiration date", () => {
5 expect(isGiftCardExpired({ expires_at: null })).toBe(false);
6 });
7
8 it("returns false when the expiration date is in the future", () => {
9 const expires_at = new Date(Date.now() + 60 * 60 * 1000).toISOString();
10
11 expect(isGiftCardExpired({ expires_at })).toBe(false);
12 });
13
14 it("returns true when the expiration date is in the past", () => {
15 const expires_at = new Date(Date.now() - 60 * 60 * 1000).toISOString();
16
17 expect(isGiftCardExpired({ expires_at })).toBe(true);
18 });
19
20 it("compares expiration dates in UTC regardless of the input's offset", () => {
21 const past = new Date(Date.now() - 60 * 60 * 1000);
22 // same instant, expressed with a non-UTC offset
23 const expires_at = past.toISOString().replace("Z", "+00:00");
24
25 expect(isGiftCardExpired({ expires_at })).toBe(true);
26 });
27 });