Skip to content

Commit

Permalink
add tests for reply function
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoyeElf committed Jan 2, 2020
1 parent 549a4a2 commit da99607
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions __tests__/receiver-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,49 @@ describe('receiver test cases', () => {
})
})

describe('should reply works normally', () => {
it('when return value is string', done => {
const { reply } = Receiver.initReceiver()
const cb = (err, data) => {
expect(err).toBeFalsy()
expect(data).toEqual({
storeType: 'direct',
isBuffer: false,
body: 'foooo'
})
done()
}
reply(cb)('foooo')
})

it('when return value is Buffer', done => {
const { reply } = Receiver.initReceiver()
const cb = (err, data) => {
expect(err).toBeFalsy()
expect(data).toEqual({
storeType: 'direct',
isBuffer: true,
body: Buffer.from('foooo').toString('base64')
})
done()
}
reply(cb)(Buffer.from('foooo'))
})

it('when return value is oss key', done => {
const { reply } = Receiver.initReceiver(false, 'oss', 10)
const cb = (err, data) => {
expect(err).toBeFalsy()
expect(data.storeType).toBe('oss')
fakeStorage.getAsBuffer(data.body).then(resp => {
expect(resp.content.toString()).toBe('fooooooooooooo')
done()
})
}
reply(cb)('fooooooooooooo')
})
})

afterAll(() => {
sandbox.reset();
const cwd = process.cwd();
Expand Down

0 comments on commit da99607

Please sign in to comment.