carotte.subscribe('stack-test-4-6', options, ({ context }) => { expect(context['origin-consumer']).to.be.deep.eql('stack-test-4-4'); expect(context.transactionStack).to.have.length(3); expect(context.transactionStack[0]).to.be.eql(stackId1); expect(context.transactionStack[1]).to.be.eql(stackId4); return true; })
it('should create a transactionStack when it\'s not defined', async () => { await carotte.subscribe('stack-test-1-1', options, ({ context }) => context.transactionStack); const context = {}; const subStack1 = await carotte.invoke('stack-test-1-1', { context }, {}); expect(subStack1).to.have.length(1); const subStack2 = await carotte.invoke('stack-test-1-1', { context }, {}); expect(subStack2).to.have.length(1); // subcalls should have different transaction stack ids expect(subStack2).to.not.deep.eql(subStack1); // subcalls should not pollute parent context transaction props expect(context.transactionStack).to.not.exist; });
it('should return serialized error with an array of JSON API error object', function(done) { const jsonapiErrors = [{ status: '422', source: { pointer: '/data/attributes/first-error' }, title: 'First Error', detail: 'First Error' }, { status: '422', source: { pointer: '/data/attributes/second-error' }, title: 'Second Error', detail: 'Second Error' }]; const serializedError = Serializer.serializeError(jsonapiErrors); expect(serializedError).to.have.property('errors').to.be.instanceof(Array).to.have.lengthOf(2); expect(serializedError.errors).to.deep.eql([{ status: '422', source: { pointer: '/data/attributes/first-error' }, title: 'First Error', detail: 'First Error' }, { status: '422', source: { pointer: '/data/attributes/second-error' }, title: 'Second Error', detail: 'Second Error' }]); done(); });
const arrs = [[1, 2], [3], [4, 5]] const flatArr = utils.flatten(arrs) expect(flatArr).to.eql([1, 2, 3, 4, 5]) }) }) expect(utils.chunk([])).to.eql([]) }) const arr = [1, 2, 3, 4, 5] const chunks = utils.chunk(arr, 2) expect(chunks).to.deep.eql([[1, 2], [3, 4], [5]]) }) }) it('should chunk number to exact slices', async function () { const chunks = utils.chunkNumber(6, 2) expect(chunks).to.eql([2, 2, 2]) }) expect(chunks).to.eql([2, 2, 2, 1]) }) })
carotte.subscribe('stack-test-4-7', options, ({ context }) => { expect(context['origin-consumer']).to.be.deep.eql('stack-test-4-4'); expect(context.transactionStack).to.have.length(3); expect(context.transactionStack[0]).to.be.eql(stackId1); expect(context.transactionStack[1]).to.be.eql(stackId4); return true; })
carotte.subscribe('stack-test-4-5', options, ({ context }) => { expect(context['origin-consumer']).to.be.deep.eql('stack-test-4-4'); expect(context.transactionStack).to.have.length(3); expect(context.transactionStack[0]).to.be.eql(stackId1); expect(context.transactionStack[1]).to.be.eql(stackId4); return true; })
expect(serializedError.errors[0]).to.deep.eql(expected);