Skip to content

Commit

Permalink
test(timestamps): break up timestamp unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zweihander-Main committed Nov 7, 2023
1 parent 67356d4 commit 693d94d
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions src/__tests__/timestamps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,45 @@ import { DateTime } from 'luxon';
import { createTimeStampData } from '../timestamps';
import { TIMEZONE, TIMESTAMP_HOUR, TIMESTAMP_MINUTE } from '../constants';

test('createTimeStampData', () => {
const { t24HrAgo, t12HrAgo } = createTimeStampData();
const today = DateTime.now().setZone(TIMEZONE);
const t24HrAgoDT = DateTime.fromSeconds(t24HrAgo);
const t12HrAgoDT = DateTime.fromSeconds(t12HrAgo);
describe('createTimeStampData', () => {
test('should return an object with t24HrAgo and t12HrAgo', () => {
const { t24HrAgo, t12HrAgo } = createTimeStampData();
expect(t24HrAgo).toBeDefined();
expect(t12HrAgo).toBeDefined();
});

expect(t24HrAgoDT.toSeconds()).toBeLessThan(t12HrAgoDT.toSeconds());
test('should have the right timezone and minutes', () => {
const { t24HrAgo, t12HrAgo } = createTimeStampData();
const t24HrAgoDT = DateTime.fromSeconds(t24HrAgo);
const t12HrAgoDT = DateTime.fromSeconds(t12HrAgo);

expect(t24HrAgoDT.minute).toBe(TIMESTAMP_MINUTE);
expect(t12HrAgoDT.minute).toBe(TIMESTAMP_MINUTE);
expect(t24HrAgoDT.setZone(TIMEZONE).toString()).toBe(t24HrAgoDT.toString());
expect(t12HrAgoDT.setZone(TIMEZONE).toString()).toBe(t12HrAgoDT.toString());
expect(t24HrAgoDT.toSeconds()).toBeLessThan(t12HrAgoDT.toSeconds());

expect(t24HrAgoDT.day).toBe(today.day - 1);
expect(t24HrAgoDT.minute).toBe(TIMESTAMP_MINUTE);
expect(t12HrAgoDT.minute).toBe(TIMESTAMP_MINUTE);
expect(t24HrAgoDT.setZone(TIMEZONE).toString()).toBe(
t24HrAgoDT.toString()
);
expect(t12HrAgoDT.setZone(TIMEZONE).toString()).toBe(
t12HrAgoDT.toString()
);
});

if (t24HrAgoDT.hour < 12) {
expect(t24HrAgoDT.hour).toBe(TIMESTAMP_HOUR);
expect(t12HrAgoDT.hour).toBe(TIMESTAMP_HOUR + 12);
expect(t24HrAgoDT.day).toBe(t12HrAgoDT.day);
} else {
expect(t24HrAgoDT.hour).toBe(TIMESTAMP_HOUR + 12);
expect(t12HrAgoDT.hour).toBe(TIMESTAMP_HOUR);
expect(t24HrAgoDT.day).toBe(t12HrAgoDT.day - 1);
}
test('should have the right hour and day', () => {
const { t24HrAgo, t12HrAgo } = createTimeStampData();
const today = DateTime.now().setZone(TIMEZONE);
const t24HrAgoDT = DateTime.fromSeconds(t24HrAgo);
const t12HrAgoDT = DateTime.fromSeconds(t12HrAgo);
expect(t24HrAgoDT.day).toBe(today.day - 1);

if (t24HrAgoDT.hour < 12) {
expect(t24HrAgoDT.hour).toBe(TIMESTAMP_HOUR);
expect(t12HrAgoDT.hour).toBe(TIMESTAMP_HOUR + 12);
expect(t24HrAgoDT.day).toBe(t12HrAgoDT.day);
} else {
expect(t24HrAgoDT.hour).toBe(TIMESTAMP_HOUR + 12);
expect(t12HrAgoDT.hour).toBe(TIMESTAMP_HOUR);
expect(t24HrAgoDT.day).toBe(t12HrAgoDT.day - 1);
}
});
});

0 comments on commit 693d94d

Please sign in to comment.