test('Invoking send() on a message lacking necessary fields', async t => { const eut = new MessageSet(); const msg = eut.newMessage(); const error = await t.throws(eut.sendMessageSet()); t.true(error instanceof errors.RequiredKeysNotSet, 'The error should be an instance of the RequiredKeysNotSet class'); });
test('Receiving an API-specific error-body from send() invocation', async t => { const eut = (new MessageStateWrapper('x', 'y')).setMessageId('abc'); eut._state.setAsCreateCompleted(); const error = await t.throws(eut.update()); t.true(error instanceof errors.BadStatusUpdateResponse, 'The error should be an instance of the BadStatusUpdateResponse class'); t.true(eut.cannotBeUpdated().error instanceof errors.BadStatusUpdateResponse); scope.done(); });
test('Invoking update() on a message that is already being updated', async t => { const eut = (new MessageStateWrapper('x', 'y')) eut._state.setAsCreateCompleted(); eut._state.setAsUpdateStarted(); const error = await t.throws(eut.update()); t.true(error instanceof errors.MessageHasAlreadyBeenUpdated, 'The error should be an instance of the MessageHasAlreadyBeenUpdated class'); });
test('dows not convert if file does not match', t => { const b = browserify(); b.transform(babelTransform({file: fixture('test', 'es2015.js')})); b.external('ava-bundler-external/process-adapter'); b.add(fixture('test', '_es2015.js')); t.throws(pify(b.bundle.bind(b), Promise)()); });
test('Receiving an API-specific error-body from send() invocation', async t => { const eut = (new MessageSet()).setApiKey('x').setUserId('y').setPlatform('z'); const msg = eut.newMessage().setMessage('abc'); const error = await t.throws(eut.sendMessageSet()); t.true(error instanceof errors.PartialPayloadFailure, 'The error should be an instance of the PartialPayloadFailure class'); scope.done(); });
test('handles API error', async t => { const client = new Client(process.env.APP_ID, process.env.REST_API_KEY); const message = 'Test Message'; const options = {}; const response = client.sendNotification(message, options); t.throws(response); });
test('invalid arg', t => { const now = 'nice' const error = t.throws(() => { goot(now) }, TypeError) t.is(error.message, 'Invalid time') })
test('Invoking send() on an already sent message', async t => { const eut = new MessageStateWrapper('x', 'y'); eut._state.setAsCreateStarted(); const error = await t.throws(eut.send()); t.true(error instanceof errors.MessageHasAlreadyBeenSent, 'The error should be an instance of the MessageHasAlreadyBeenSent class'); });
test('Invoking send() on a message lacking necessary fields', async t => { const eut = new MessageStateWrapper(); const error = await t.throws(eut.send()); t.true(error instanceof errors.RequiredKeysNotSet, 'The error should be an instance of the RequiredKeysNotSet class'); });
test('throws an error if no message is provided', async t => { const message = ''; const options = { included_segments: 'all' }; const response = client.sendNotification(message, options); t.throws(response, '`message` is required'); });
test('Invoking update() on a message that cannot be updated', async t => { const eut = (new MessageStateWrapper('x', 'y')); eut._state.setAsCreateErrored({error: new Error('500')}); const error = await t.throws(eut.update()); t.true(error instanceof errors.MessageCannotBeUpdated, 'The error should be an instance of the MessageCannotBeUpdated class'); });
test('throws an error if no api key is specified', t => { t.throws(() => { new Client('a0944967-e2b6-4549-91d2-91fdd290ad94'); }, '`restApiKey` is required'); });
test('Invoking send() on an already sent message', async t => { const eut = new MessageSet(); eut._state.setAsCreateStarted(); const error = await t.throws(eut.sendMessageSet()); t.true(error instanceof errors.MessageSetHasAlreadyBeenSent, 'The error should be an instance of the MessageSetHasAlreadyBeenSent class'); });
test('Invoking update() on a message that has not been sent', async t => { const eut = new MessageStateWrapper('x', 'y'); const error = await t.throws(eut.update()); t.true(error instanceof errors.MessageMustBeSentBeforeBeingUpdated, 'The error should be an instance of the MessageMustBeSentBeforeBeingUpdated class'); });
test('Receiving a 200-OK without body', async t => { const eut = (new MessageSet()).setApiKey('x').setUserId('y').setPlatform('z'); const msg = eut.newMessage().setMessage('abc'); const error = await t.throws(eut.sendMessageSet()); t.true(error instanceof errors.EmptyCreateResponse, 'The error should be an instance of the EmptyCreateResponse class'); scope.done(); });