1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: inital event.tags should be array type

This commit is contained in:
Ivar Conradi Østhus 2021-03-18 09:48:11 +01:00
parent 3a122a3f97
commit 6d8ccaf88b
No known key found for this signature in database
GPG Key ID: 31AC596886B0BD09
2 changed files with 32 additions and 8 deletions

View File

@ -24,12 +24,7 @@ class EventStore extends EventEmitter {
async store(event) { async store(event) {
try { try {
const rows = await this.db(TABLE) const rows = await this.db(TABLE)
.insert({ .insert(this.eventToDbRow(event))
type: event.type,
created_by: event.createdBy, // eslint-disable-line
data: event.data,
tags: event.tags ? JSON.stringify(event.tags) : [],
})
.returning(EVENT_COLUMNS); .returning(EVENT_COLUMNS);
const savedEvent = this.rowToEvent(rows[0]); const savedEvent = this.rowToEvent(rows[0]);
process.nextTick(() => this.emit(event.type, savedEvent)); process.nextTick(() => this.emit(event.type, savedEvent));
@ -104,7 +99,7 @@ class EventStore extends EventEmitter {
type: e.type, type: e.type,
created_by: e.createdBy, created_by: e.createdBy,
data: e.data, data: e.data,
tags: e.tags ? JSON.stringify(e.tags) : [], tags: JSON.stringify(e.tags || []),
}; };
} }
} }

View File

@ -2,7 +2,10 @@
const test = require('ava'); const test = require('ava');
const sinon = require('sinon'); const sinon = require('sinon');
const { APPLICATION_CREATED } = require('../../../lib/event-type'); const {
APPLICATION_CREATED,
FEATURE_CREATED,
} = require('../../../lib/event-type');
const dbInit = require('../helpers/database-init'); const dbInit = require('../helpers/database-init');
const getLogger = require('../../fixtures/no-logger'); const getLogger = require('../../fixtures/no-logger');
@ -40,6 +43,32 @@ test.serial('Should include id and createdAt when saving', async t => {
t.is(seen[0].data.appName, event1.data.appName); t.is(seen[0].data.appName, event1.data.appName);
}); });
test.serial('Should include empty tags array for new event', async t => {
t.plan(2);
const event = {
type: FEATURE_CREATED,
createdBy: 'me@mail.com',
data: {
name: 'someName',
enabled: true,
strategies: [{ name: 'default' }],
},
};
const promise = new Promise(resolve => {
eventStore.on(FEATURE_CREATED, storedEvent => {
t.is(storedEvent.name, event.name);
t.true(Array.isArray(storedEvent.tags), 'tags should be an array');
resolve();
});
});
// Trigger
await eventStore.store(event);
return promise;
});
test.serial('Should be able to store multiple events at once', async t => { test.serial('Should be able to store multiple events at once', async t => {
const clock = sinon.useFakeTimers(); const clock = sinon.useFakeTimers();
const event1 = { const event1 = {