Skip to content

Commit

Permalink
fix: remove meta tag in streaming handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Dec 20, 2024
1 parent 098551c commit 9409987
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
8 changes: 1 addition & 7 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,7 @@ export default class Repository extends EventEmitter implements EventEmitter {
if (this.eventSource) {
this.eventSource.addEventListener('unleash-updated', (event: { data: string }) => {
try {
const data: ClientFeaturesResponse & { meta: { etag: string } } = JSON.parse(event.data);
const etag = data.meta.etag;
if (etag !== null) {
this.etag = etag;
} else {
this.etag = undefined;
}
const data: ClientFeaturesResponse = JSON.parse(event.data);
this.save(data, true);
} catch (err) {
this.emit(UnleashEvents.Error, err);
Expand Down
11 changes: 3 additions & 8 deletions src/test/repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ test('Stopping repository should stop storage provider updates', async (t) => {
});

test('Streaming', async (t) => {
t.plan(6);
t.plan(4);
const url = 'irrelevant';
const feature = {
name: 'feature',
Expand Down Expand Up @@ -1408,22 +1408,17 @@ test('Streaming', async (t) => {
// update with feature
eventSource.emit('unleash-updated', {
type: 'unleash-updated',
data: JSON.stringify({ meta: {}, features: [feature] }),
data: JSON.stringify({ features: [feature] }),
});
const firstUpdate = repo.getToggles();
t.deepEqual(firstUpdate, [feature]);
// @ts-expect-error
t.is(repo.etag, undefined);

// update with etag
eventSource.emit('unleash-updated', {
type: 'unleash-updated',
data: JSON.stringify({ meta: { etag: 'updated' }, features: [] }),
data: JSON.stringify({ features: [] }),
});
const secondUpdate = repo.getToggles();
t.deepEqual(secondUpdate, []);
// @ts-expect-error
t.is(repo.etag, 'updated');

// SSE error translated to repo warning
repo.on('warn', (msg) => {
Expand Down

0 comments on commit 9409987

Please sign in to comment.