UNPKG

@intocode-io/line-api-cli

Version:
56 lines (46 loc) 1.6 kB
import Axios from 'axios'; import LINETvGetStationRequest from '../linetv-get-station-request'; describe('LINEGetSpotLightRequest', () => { describe('when create an instance with options.accessToken', () => { let req; let accessToken = 'someaccesstoken'; beforeAll(() => { jest.spyOn(Axios, 'create'); req = new LINETvGetStationRequest({ accessToken }); }); it('should have correct endpoint', () => { expect(req.endpoint).toEqual('https://api.line.me/line-tv/v1/station'); }); 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', () => { const channelId = '1234'; const countryCode = 'th'; const stationId = 'station'; const page = 1; beforeAll(() => { jest.spyOn(req.axios, 'get').mockResolvedValue('any'); req.send(channelId, countryCode, stationId); }); it('should call to correct endpoint', () => { expect(req.axios.get).toHaveBeenCalledTimes(1); expect(req.axios.get).toHaveBeenCalledWith( `${req.endpoint}?lineChannelId=${channelId}&country=${countryCode}&stationId=${stationId}&page=${page}` ); }); afterAll(() => { req.axios.get.mockRestore(); }); }); afterAll(() => { Axios.create.mockRestore(); }); }); });