line-api-cli
Version:
LINE API CLIs for Node.js
55 lines (44 loc) • 1.46 kB
JavaScript
import Axios from 'axios';
import ThingsGetDeviceRequest from '../things-get-device-request';
describe('ThingsGetDeviceRequest', () => {
describe('when create an instance with options.accessToken', () => {
let req;
let accessToken = 'someaccesstoken';
beforeAll(() => {
jest.spyOn(Axios, 'create');
req = new ThingsGetDeviceRequest({ accessToken });
});
it('should have correct endpoint', () => {
expect(req.endpoint).toEqual('https://api.line.me/things/v1');
});
it('should create axios instance with correct headers for LINE API', () => {
expect(Axios.create).toHaveBeenCalledWith({
headers: {
authorization: `Bearer ${accessToken}`,
'content-type': 'application/json'
}
});
expect(req.axios).toBeDefined();
});
describe('when send a request', () => {
let deviceId = 'xxxx';
let userId = 'yyyy';
beforeAll(() => {
jest.spyOn(req.axios, 'get').mockResolvedValue('any');
req.send(deviceId, userId);
});
it('should call to correct endpoint', () => {
expect(req.axios.get).toHaveBeenCalledTimes(1);
expect(req.axios.get).toHaveBeenCalledWith(
`https://api.line.me/things/v1/devices/${deviceId}`
);
});
afterAll(() => {
req.axios.get.mockRestore();
});
});
afterAll(() => {
Axios.create.mockRestore();
});
});
});