Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(splito-api-binding): ensure latest splits are saved and add tests #15

Merged
merged 3 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/data-serializer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

const Poller = require('./poller')
celiawaggoner marked this conversation as resolved.
Show resolved Hide resolved
const { SplitioApiBinding } = require('./splitio-api-binding')

class DataSerializer {
constructor ({ poller }) {
this.poller = poller
Expand Down
5 changes: 3 additions & 2 deletions lib/splitio-api-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ class SplitioApiBinding {
const { allChanges, since } = await this.getAllChanges({ path })
allChanges.forEach(change => {
change.splits.forEach(split => {
if (split.status !== 'ARCHIVED') {
splits[split.name] = split
splits[split.name] = split
jh2oman marked this conversation as resolved.
Show resolved Hide resolved
if (split.status === 'ARCHIVED') {
delete splits[split.name]
}
})
})
Expand Down
45 changes: 45 additions & 0 deletions lib/splitio-api-binding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ describe('lib.splitio-api-binding', () => {
describe('getSplits', () => {
const mockSplit0 = { name: 'mockSplit0', status: 'bar' }
const mockSplit1 = { name: 'mockSplit1', status: 'baz' }
const mockSplit1Updated = { name: 'mockSplit1', status: 'zoo' }
const mockSplit2 = { name: 'mockSplit2', status: 'ARCHIVED' }
const mockSplit3 = { name: 'mockSplit3', status: 'zaz' }
const mockSplit3Updated = { name: 'mockSplit3', status: 'ARCHIVED' }
it('returns all active splits and the since value', async () => {
const splitioApiBinding = new SplitioApiBinding({ splitioApiKey: 'foo' })
const requestStub = sinon.stub()
Expand All @@ -166,6 +169,48 @@ describe('lib.splitio-api-binding', () => {
})
})

it('overwrites an existing split object will the latest data from a subsequent request', async () => {
celiawaggoner marked this conversation as resolved.
Show resolved Hide resolved
const splitioApiBinding = new SplitioApiBinding({ splitioApiKey: 'foo' })
const requestStub = sinon.stub()
splitioApiBinding.getAllChanges = requestStub
requestStub.onCall(0).resolves({
allChanges: [
{ splits: [mockSplit0, mockSplit1], till: 0 },
{ splits: [mockSplit1Updated, mockSplit3], till: 1 }
],
since: 1
})
const splits = await splitioApiBinding.getSplits({ path: '/splitChanges' })
expect(splits).deep.equals({
splits: {
mockSplit0,
mockSplit1: mockSplit1Updated,
mockSplit3
},
since: 1
})
})

it('does not save a split that was archived after the initial request to GET /splitChanges', async () => {
const splitioApiBinding = new SplitioApiBinding({ splitioApiKey: 'foo' })
const requestStub = sinon.stub()
splitioApiBinding.getAllChanges = requestStub
requestStub.onCall(0).resolves({
allChanges: [
{ splits: [mockSplit0, mockSplit3], till: 0 },
{ splits: [mockSplit3Updated], till: 1 }
],
since: 1
})
const splits = await splitioApiBinding.getSplits({ path: '/splitChanges' })
expect(splits).deep.equals({
splits: {
mockSplit0
},
since: 1
})
})

it('throws an error on an error from getAllChanges', async () => {
const splitioApiBinding = new SplitioApiBinding({ splitioApiKey: 'foo' })
const requestStub = sinon.stub()
Expand Down