2019-12-11 15:27:06 +00:00
|
|
|
import endPoints from '../endPoints';
|
|
|
|
|
|
|
|
describe('#sendMessage', () => {
|
|
|
|
it('returns correct payload', () => {
|
2020-01-01 17:00:43 +00:00
|
|
|
const spy = jest.spyOn(global, 'Date').mockImplementation(() => ({
|
|
|
|
toString: () => 'mock date',
|
|
|
|
}));
|
2020-12-12 06:38:36 +00:00
|
|
|
const windowSpy = jest.spyOn(window, 'window', 'get');
|
|
|
|
windowSpy.mockImplementation(() => ({
|
|
|
|
WOOT_WIDGET: {
|
|
|
|
$root: {
|
|
|
|
$i18n: {
|
|
|
|
locale: 'ar',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
location: {
|
|
|
|
search: '?param=1',
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2019-12-11 15:27:06 +00:00
|
|
|
expect(endPoints.sendMessage('hello')).toEqual({
|
2020-12-12 06:38:36 +00:00
|
|
|
url: `/api/v1/widget/messages?param=1&locale=ar`,
|
2019-12-11 15:27:06 +00:00
|
|
|
params: {
|
|
|
|
message: {
|
|
|
|
content: 'hello',
|
2020-01-01 17:00:43 +00:00
|
|
|
referer_url: '',
|
|
|
|
timestamp: 'mock date',
|
2019-12-11 15:27:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-12-12 06:38:36 +00:00
|
|
|
windowSpy.mockRestore();
|
2020-01-01 17:00:43 +00:00
|
|
|
spy.mockRestore();
|
2019-12-11 15:27:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#getConversation', () => {
|
|
|
|
it('returns correct payload', () => {
|
|
|
|
expect(endPoints.getConversation({ before: 123 })).toEqual({
|
|
|
|
url: `/api/v1/widget/messages`,
|
|
|
|
params: {
|
|
|
|
before: 123,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|