it('formatParams should ok', function () { const formatParams = rpc.__get__('formatParams'); expect(formatParams({'hello': 'world'})).to.be.eql({ Hello: 'world' }); });
describe('request', function () { mock({ req: { _headers: {} } }, '{}'); it('get with raw body should ok', async function () { const client = new RPCClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', }); const result = await client.request('action', {}); expect(result).to.be.eql({}); }); });
it('replaceRepeatList should ok', function () { const replaceRepeatList = rpc.__get__('replaceRepeatList'); function helper(target, key, repeat) { replaceRepeatList(target, key, repeat); return target; } expect(helper({}, 'key', [])).to.be.eql({}); expect(helper({}, 'key', ['value'])).to.be.eql({ 'key.1': 'value' }); expect(helper({}, 'key', [{ Domain: '1.com' }])).to.be.eql({ 'key.1.Domain': '1.com' }); });
it('works with compression applied in serializer', function() { const dictionary = Buffer.from('"metadata":{"committedAt":,"commitId":,"commitVersion":,"streamVersion":{"stream":"Event-0f0da93d-260a-4ffd-94a0-126bd67ee8ff","payload":{"type":,"metadata":{"occuredAt":'); storage = createStorage({ serializer: { serialize: (doc) => { return zlib.deflateRawSync(Buffer.from(JSON.stringify(doc)), { dictionary }).toString('binary'); //return lz4.encode(Buffer.from(JSON.stringify(doc))).toString('binary'); }, deserialize: (string) => { return JSON.parse(zlib.inflateRawSync(Buffer.from(string, 'binary'), { dictionary }).toString()); //return JSON.parse(lz4.decode(Buffer.from(string, 'binary'))); } }}); storage.open(); const doc = {"stream":"Event-0f0da93d-260a-4ffd-94a0-126bd67ee8ff","payload":{"type":"DomainEvent","payload":{"type":"EventCreated","payload":{"eventIdentifier":"0f0da93d-260a-4ffd-94a0-126bd67ee8ff","name":"testi"}},"metadata":{"occuredAt":1482764928713,"aggregateId":"0f0da93d-260a-4ffd-94a0-126bd67ee8ff","version":0,"type":"EventCreated","correlationId":"9242b72b-03a0-4078-ae62-f37af7cb1b39"}},"metadata":{"committedAt":1482764928715,"commitId":1,"commitVersion":0,"streamVersion":0}}; storage.write(doc); storage.write(doc); expect(storage.read(1)).to.be.eql(doc); expect(storage.read(2)).to.be.eql(doc); });
describe('delete should ok', function () { mock({ statusCode: 200, headers: { 'content-type': 'application/json' } }, JSON.stringify({'ok': true})); it('should ok', async function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', securityToken: 'securityToken' }); const result = await client.delete('/', {}, {}, {}); expect(result).to.be.eql({'ok': true}); }); });
describe('Datatype', function() { _.each(datatypes, function(dt, key) { describe(`"${key}"`, function() { it('should pass self-validation', function() { let params; if ( ['set', 'enum'].includes(key) ) { params = Object.assign({}, dt.defaults, { options: ['one'] }); } else { params = dt.defaults; } return mitra.validate(params, dt.rules).catch(e => { throw new Error(JSON.stringify(e.errors)); }); }); }); }); _.each(examples, function(props, dtName) { describe(`"${dtName}".generateSQL()`, function() { it('should generate expected SQL', function() { expect( datatypes[dtName].generateSQL(props.params) ).to.be.eql( props.sql ); }); }); }); });
it('parseXML should ok', async function () { const parseXML = roa.__get__('parseXML'); const result = await parseXML(`<note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>`); expect(result).to.be.eql({ 'note': { 'body': [ "Don't forget the meeting!" ], 'from': [ 'John' ], 'heading': [ 'Reminder' ], 'to': [ 'George' ] } }); });
it('is empty when stream does not exist', function(){ stream = new EventStream('bar', mockEventStore); expect(stream.events).to.be.eql([]); });
it('normalize should ok', function () { const normalize = rpc.__get__('normalize'); expect(normalize({})).to.be.eql([]); expect(normalize({key: ['value']})).to.be.eql([ ['key.1', 'value'] ]); expect(normalize({ 'key': 'value' })).to.be.eql([ ['key', 'value'] ]); expect(normalize({ key: [ { Domain: '1.com' } ] })).to.be.eql([ ['key.1.Domain', '1.com'] ]); expect(normalize({ 'a': 'value', 'c': 'value', 'b': 'value' })).to.be.eql([ ['a', 'value'], ['b', 'value'], ['c', 'value'] ]); });
it('flatParams should ok', function () { const flatParams = rpc.__get__('flatParams'); expect(flatParams({})).to.be.eql({}); expect(flatParams({key: ['value']})).to.be.eql({ 'key.1': 'value' }); expect(flatParams({ 'key': 'value' })).to.be.eql({ 'key': 'value' }); expect(flatParams({ key: [ { Domain: '1.com' } ] })).to.be.eql({ 'key.1.Domain': '1.com' }); });
describe('put should ok', function () { mock({ statusCode: 200, headers: { 'content-type': 'application/json' } }, JSON.stringify({'ok': true})); it('should ok', async function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', securityToken: 'securityToken' }); const result = await client.put('/', {}, 'text', {}, {}); expect(result).to.be.eql({'ok': true}); }); });
it('is empty when stream does not exist', function(){ stream = new JoinEventStream('foo-bar', ['baz'], eventstore); expect(stream.events).to.be.eql([]); });
describe('request with json response should ok', function () { mock({ statusCode: 200, headers: { 'content-type': 'application/json' } }, JSON.stringify({'ok': true})); it('json response should ok', async function () { const client = new ROAClient({ endpoint: 'https://ecs.aliyuncs.com/', apiVersion: '1.0', accessKeyId: 'accessKeyId', accessKeySecret: 'accessKeySecret', securityToken: 'securityToken' }); const result = await client.request('GET', '/'); expect(result).to.be.eql({ ok: true }); }); });