eventlog: add params for from and to date
This commit is contained in:
@@ -47,7 +47,7 @@ describe('Eventlog', function () {
|
||||
});
|
||||
|
||||
it('listPaged succeeds', async function () {
|
||||
const results = await eventlog.listPaged([], null, 1, 1);
|
||||
const results = await eventlog.listPaged({ actions: [], search: null }, 1, 1);
|
||||
expect(results).to.be.an(Array);
|
||||
expect(results.length).to.be(1);
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('Eventlog', function () {
|
||||
});
|
||||
|
||||
it('listPaged succeeds with source search', async function () {
|
||||
const results = await eventlog.listPaged([], '1.2.3.4', 1, 1);
|
||||
const results = await eventlog.listPaged({ actions: [], search: '1.2.3.4' }, 1, 1);
|
||||
expect(results).to.be.an(Array);
|
||||
expect(results.length).to.be(1);
|
||||
expect(results[0].id).to.be(eventId);
|
||||
@@ -68,7 +68,7 @@ describe('Eventlog', function () {
|
||||
});
|
||||
|
||||
it('listPaged succeeds with data search', async function () {
|
||||
const results = await eventlog.listPaged([], 'thatapp', 1, 1);
|
||||
const results = await eventlog.listPaged({ actions: [], search: 'thatapp' }, 1, 1);
|
||||
expect(results).to.be.an(Array);
|
||||
expect(results.length).to.be(1);
|
||||
expect(results[0].id).to.be(eventId);
|
||||
@@ -77,6 +77,26 @@ describe('Eventlog', function () {
|
||||
expect(results[0].data).to.be.eql({ appId: 'thatapp' });
|
||||
});
|
||||
|
||||
it('listPaged succeeds with from/to time filter', async function () {
|
||||
const event = await eventlog.get(eventId);
|
||||
const creationTime = event.creationTime;
|
||||
const from = new Date(creationTime.getTime() - 60000); // 1 min before
|
||||
const to = new Date(creationTime.getTime() + 60000); // 1 min after
|
||||
|
||||
const results = await eventlog.listPaged({ actions: [], search: null, from, to }, 1, 10);
|
||||
expect(results).to.be.an(Array);
|
||||
expect(results.length).to.be.above(0);
|
||||
expect(results.some((r) => r.id === eventId)).to.be(true);
|
||||
});
|
||||
|
||||
it('listPaged returns empty with from after event', async function () {
|
||||
const event = await eventlog.get(eventId);
|
||||
const from = new Date(event.creationTime.getTime() + 86400000); // 1 day after
|
||||
|
||||
const results = await eventlog.listPaged({ actions: [], search: null, from }, 1, 10);
|
||||
expect(results.some((r) => r.id === eventId)).to.be(false);
|
||||
});
|
||||
|
||||
let loginEventId;
|
||||
it('upsert with no existing entry succeeds', async function () {
|
||||
const result = await eventlog.upsertLoginEvent('user.login', { ip: '1.2.3.4' }, { appId: 'thatapp' });
|
||||
@@ -121,7 +141,7 @@ describe('Eventlog', function () {
|
||||
const id = await eventlog.add(eventlog.ACTION_USER_LOGIN, { ip: '1.2.3.4' }, { appId: 'thatapp' });
|
||||
|
||||
await eventlog.cleanup({ creationTime: new Date(Date.now() - 1000) }); // 1 second ago
|
||||
let results = await eventlog.listPaged([], null, 1, 100);
|
||||
let results = await eventlog.listPaged({ actions: [], search: null }, 1, 100);
|
||||
expect(results.length).to.be(1);
|
||||
|
||||
expect(results[0].id).to.be(id);
|
||||
|
||||
@@ -28,4 +28,20 @@ describe('Validator', function () {
|
||||
for (const badEmail of badEmails) {
|
||||
it(`isEmail returns false ${badEmail}`, () => expect(validator.isEmail(badEmail)).to.be(false));
|
||||
}
|
||||
|
||||
describe('isIsoDate', function () {
|
||||
it('returns true for valid ISO string', function () {
|
||||
expect(validator.isIsoDate('2024-01-15T10:30:00.000Z')).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false for invalid string', function () {
|
||||
expect(validator.isIsoDate('not-a-date')).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false for empty or non-string', function () {
|
||||
expect(validator.isIsoDate('')).to.be(false);
|
||||
expect(validator.isIsoDate(null)).to.be(false);
|
||||
expect(validator.isIsoDate(undefined)).to.be(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user