Skip to content

Commit 60a4856

Browse files
Add more tests to discourage bad implementations (#2663)
1 parent 3f3cdde commit 60a4856

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

exercises/concept/appointment-time/appointment-time.spec.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ describe('createAppointment', () => {
3939
27 * 60 * 60 * 1000,
4040
);
4141
});
42+
43+
test('rolls over days, months, and years', () => {
44+
const currentTime = Date.UTC(1991, 16, 6, 2, 12, 0, 0);
45+
const result = createAppointment(720, currentTime);
46+
47+
expect(result.getTime()).toStrictEqual(767326320000);
48+
});
4249
});
4350

4451
describe('getAppointmentTimestamp', () => {
@@ -52,7 +59,7 @@ describe('getAppointmentTimestamp', () => {
5259
});
5360

5461
describe('getAppointment', () => {
55-
test('get appointment detail', () => {
62+
test('extracts appointment details', () => {
5663
expect(getAppointmentDetails('2022-04-24T08:15:00.000')).toStrictEqual({
5764
year: 2022,
5865
month: 3,
@@ -64,13 +71,13 @@ describe('getAppointment', () => {
6471
});
6572

6673
describe('updateAppointment', () => {
67-
test('should update with one option', () => {
74+
test('updates a field', () => {
6875
expect(
6976
updateAppointment('2022-02-09T09:20:00.000', { month: 6 }),
7077
).toStrictEqual({ year: 2022, month: 6, date: 9, hour: 9, minute: 20 });
7178
});
7279

73-
test('should update with multiple options', () => {
80+
test('update multiple fields', () => {
7481
expect(
7582
updateAppointment('2022-11-21T21:20:00.000', {
7683
year: 2023,
@@ -82,39 +89,51 @@ describe('updateAppointment', () => {
8289
).toStrictEqual({ year: 2023, month: 1, date: 12, hour: 1, minute: 29 });
8390
});
8491

85-
test('should update with option with zero as value', () => {
92+
test('updates even if option is 0', () => {
8693
expect(
8794
updateAppointment('2022-12-17T07:10:00.000', { minute: 0 }),
8895
).toStrictEqual({ year: 2022, month: 11, date: 17, hour: 7, minute: 0 });
8996
});
97+
98+
test('rolls over values', () => {
99+
expect(
100+
updateAppointment('2029-02-28T23:59:00.000', { hour: 24, minute: 60 }),
101+
).toStrictEqual({ year: 2029, month: 2, date: 1, hour: 1, minute: 0 });
102+
});
90103
});
91104

92105
describe('availableTimes', () => {
93-
test('get available times between two appointments', () => {
106+
test('retrieves number of seconds between two appointments', () => {
94107
expect(
95108
timeBetween('2022-12-12T09:20:00.000', '2022-12-18T08:30:00.000'),
96109
).toBe(515400);
97110
});
111+
112+
test('rounds to seconds', () => {
113+
expect(
114+
timeBetween('2024-03-06T09:12:15.180', '2024-03-06T18:15:12.090'),
115+
).toBe(32577);
116+
});
98117
});
99118

100119
describe('isValid', () => {
101-
test('true when appointment datetime is in the future', () => {
120+
test('is true when appointment datetime is in the future', () => {
102121
expect(isValid('2022-02-11T23:00:00.000', '2022-02-08T23:00:00.000')).toBe(
103122
true,
104123
);
105124
});
106125

107-
test('true when appointment date is in the future', () => {
126+
test('is true when appointment date is in the future', () => {
108127
expect(isValid('2022-02-11', '2022-02-08')).toBe(true);
109128
});
110129

111-
test('false when appointment datetime is in the past', () => {
130+
test('is false when appointment datetime is in the past', () => {
112131
expect(isValid('2022-05-20T23:00:00.000', '2023-02-08T23:00:00.000')).toBe(
113132
false,
114133
);
115134
});
116135

117-
test('false when appointment date is in the past', () => {
136+
test('is false when appointment date is in the past', () => {
118137
expect(isValid('2022-05-21', '2022-05-22')).toBe(false);
119138
});
120139
});

0 commit comments

Comments
 (0)