Skip to content

Commit 07d57be

Browse files
committed
add 4 more tests to increase the test robustness
1 parent 9f74941 commit 07d57be

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

test/integration/progressesTasks.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("Test Progress Updates API for Tasks", function () {
5252
clock.restore();
5353
});
5454

55-
it("Stores the progress entry for the task", function (done) {
55+
it("Stores the task progress entry", function (done) {
5656
chai
5757
.request(app)
5858
.post(`/progresses`)
@@ -80,6 +80,36 @@ describe("Test Progress Updates API for Tasks", function () {
8080
});
8181
});
8282

83+
it("stores the user progress document for the previous day if the update is sent before 6am IST", function (done) {
84+
clock.setSystemTime(new Date(Date.UTC(2023, 4, 2, 0, 29)).getTime()); // 2nd May 2023 05:59 am IST
85+
chai
86+
.request(app)
87+
.post(`/progresses`)
88+
.set("cookie", `${cookieName}=${userToken}`)
89+
.send(taskProgressDay1(taskId2))
90+
.end((err, res) => {
91+
if (err) return done(err);
92+
expect(res).to.have.status(201);
93+
expect(res.body.data.date).to.be.equal(1682899200000); // 1st May 2023
94+
return done();
95+
});
96+
});
97+
98+
it("stores the user progress document for the current day if the update is sent after 6am IST", function (done) {
99+
clock.setSystemTime(new Date(Date.UTC(2023, 4, 2, 0, 31)).getTime()); // 2nd May 2023 06:01 am IST
100+
chai
101+
.request(app)
102+
.post(`/progresses`)
103+
.set("cookie", `${cookieName}=${userToken}`)
104+
.send(taskProgressDay1(taskId2))
105+
.end((err, res) => {
106+
if (err) return done(err);
107+
expect(res).to.have.status(201);
108+
expect(res.body.data.date).to.be.equal(1682985600000); // 2nd May 2023
109+
return done();
110+
});
111+
});
112+
83113
it("throws Conflict Error 409 if the task progress is updated multiple times in a day", function (done) {
84114
chai
85115
.request(app)

test/integration/progressesUsers.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("Test Progress Updates API for Users", function () {
4747
clock.restore();
4848
});
4949

50-
it("stores the user progress document for the first time", function (done) {
50+
it("stores the user progress document", function (done) {
5151
chai
5252
.request(app)
5353
.post(`/progresses`)
@@ -73,6 +73,36 @@ describe("Test Progress Updates API for Users", function () {
7373
});
7474
});
7575

76+
it("stores the user progress document for the previous day if the update is sent before 6am IST", function (done) {
77+
clock.setSystemTime(new Date(Date.UTC(2023, 4, 2, 0, 29)).getTime()); // 2nd May 2023 05:59 am IST
78+
chai
79+
.request(app)
80+
.post(`/progresses`)
81+
.set("cookie", `${cookieName}=${userToken}`)
82+
.send(standupProgressDay1)
83+
.end((err, res) => {
84+
if (err) return done(err);
85+
expect(res).to.have.status(201);
86+
expect(res.body.data.date).to.be.equal(1682899200000); // 1st May 2023
87+
return done();
88+
});
89+
});
90+
91+
it("stores the user progress document for the current day if the update is sent after 6am IST", function (done) {
92+
clock.setSystemTime(new Date(Date.UTC(2023, 4, 2, 0, 31)).getTime()); // 2nd May 2023 06:01 am IST
93+
chai
94+
.request(app)
95+
.post(`/progresses`)
96+
.set("cookie", `${cookieName}=${userToken}`)
97+
.send(standupProgressDay1)
98+
.end((err, res) => {
99+
if (err) return done(err);
100+
expect(res).to.have.status(201);
101+
expect(res.body.data.date).to.be.equal(1682985600000); // 2nd May 2023
102+
return done();
103+
});
104+
});
105+
76106
it("throws Conflict Error 409 if the user tries to update progress multiple times in a single day", function (done) {
77107
chai
78108
.request(app)

utils/progresses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const progressesCollection = fireStore.collection("progresses");
1616
const getProgressDateTimestamp = () => {
1717
// Currently, we are primarily catering to Indian users for our apps, which is why we have implemented support for the IST (Indian Standard Time) timezone for progress updates.
1818
const currentHourIST = new Date().getUTCHours() + 5.5; // IST offset is UTC+5:30;
19-
const isBefore6amIST = currentHourIST < 6;
19+
const isBefore6amIST = currentHourIST === 5.5 && new Date().getUTCMinutes() <= 30;
2020
return isBefore6amIST ? new Date().setUTCHours(0, 0, 0, 0) - MILLISECONDS_IN_DAY : new Date().setUTCHours(0, 0, 0, 0);
2121
};
2222

0 commit comments

Comments
 (0)