Skip to content

Commit

Permalink
make created timestamp second precision. Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Feb 22, 2024
1 parent d6d6307 commit 4097dab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/api/autoreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ module.exports = (db, server) => {
}

result.value.created = new Date();
result.value.created.setMilliseconds(0);
result.value.created = result.value.created.toISOString();

const autoreplyData = await db.database
.collection('autoreplies')
Expand Down Expand Up @@ -234,7 +236,7 @@ module.exports = (db, server) => {
html: entry.html || '',
start: entry.start || false,
end: entry.end || false,
created: entry.created || entry._id.getTimestamp()
created: entry.created || entry._id?.getTimestamp() || false
});
})
);
Expand Down
15 changes: 11 additions & 4 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chai.config.includeStack = true;
const config = require('wild-config');

const server = supertest.agent(`http://127.0.0.1:${config.api.port}`);
const ObjectId = require('mongodb').ObjectId;

describe('API tests', function () {
let userId, asp, address, inbox;
Expand Down Expand Up @@ -416,7 +417,8 @@ describe('API tests', function () {
text: '',
html: '',
start: false,
end: false
end: false,
created: false
});

r = await server
Expand All @@ -432,6 +434,8 @@ describe('API tests', function () {
.expect(200);
expect(r.body.success).to.be.true;

const autoreplyId = new ObjectId(r.body._id);

r = await server.get(`/users/${userId}/autoreply`).expect(200);
expect(r.body).to.deep.equal({
success: true,
Expand All @@ -441,7 +445,8 @@ describe('API tests', function () {
text: 'Away from office until Dec.19',
html: '',
start: '2017-11-15T00:00:00.000Z',
end: '2017-12-19T00:00:00.000Z'
end: '2017-12-19T00:00:00.000Z',
created: autoreplyId.getTimestamp().toISOString()
});

r = await server
Expand All @@ -463,7 +468,8 @@ describe('API tests', function () {
text: 'Away from office until Dec.19',
html: '',
start: false,
end: '2017-12-19T00:00:00.000Z'
end: '2017-12-19T00:00:00.000Z',
created: autoreplyId.getTimestamp().toISOString()
});

await server.delete(`/users/${userId}/autoreply`).expect(200);
Expand All @@ -476,7 +482,8 @@ describe('API tests', function () {
text: '',
html: '',
start: false,
end: false
end: false,
created: false
});
});
});
Expand Down

0 comments on commit 4097dab

Please sign in to comment.