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