bigbuffet-rw/app/soapbox/utils/__tests__/ads.test.ts

24 lines
783 B
TypeScript
Raw Normal View History

2023-05-02 16:30:21 -07:00
import { buildAd } from 'soapbox/jest/factory';
import { isExpired } from '../ads';
/** 3 minutes in milliseconds. */
const threeMins = 3 * 60 * 1000;
/** 5 minutes in milliseconds. */
const fiveMins = 5 * 60 * 1000;
test('isExpired()', () => {
const now = new Date();
2022-10-20 14:29:14 -07:00
const iso = now.toISOString();
const epoch = now.getTime();
// Sanity tests.
2023-05-02 16:30:21 -07:00
expect(isExpired(buildAd({ expires_at: iso }))).toBe(true);
expect(isExpired(buildAd({ expires_at: new Date(epoch + 999999).toISOString() }))).toBe(false);
// Testing the 5-minute mark.
2023-05-02 16:30:21 -07:00
expect(isExpired(buildAd({ expires_at: new Date(epoch + threeMins).toISOString() }), fiveMins)).toBe(true);
expect(isExpired(buildAd({ expires_at: new Date(epoch + fiveMins + 1000).toISOString() }), fiveMins)).toBe(false);
});