UNPKG

ask-cli

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

55 lines (48 loc) 2.01 kB
const { expect } = require('chai'); const sinon = require('sinon'); const httpClient = require('@src/clients/http-client'); const AuthorizationController = require('@src/controllers/authorization-controller'); const CONSTANTS = require('@src/utils/constants'); const noop = () => {}; module.exports = (smapiClient) => { describe('# smapi client vendor APIs', () => { let httpClientStub; const TEST_PROFILE = 'testProfile'; const TEST_ACCESS_TOKEN = 'access_token'; beforeEach(() => { httpClientStub = sinon.stub(httpClient, 'request').callsFake(noop); sinon.stub(AuthorizationController.prototype, 'tokenRefreshAndRead'); }); [ { testCase: 'list-vendors', apiFunc: smapiClient.vendor.listVendors, parameters: [noop], expectedOptions: { url: `${CONSTANTS.SMAPI.ENDPOINT}/v1/vendors`, method: CONSTANTS.HTTP_REQUEST.VERB.GET, headers: { authorization: TEST_ACCESS_TOKEN }, body: null, json: false } } ].forEach(({ testCase, apiFunc, parameters, expectedOptions }) => { it(`| call ${testCase} successfully`, (done) => { // setup AuthorizationController.prototype.tokenRefreshAndRead.callsArgWith(1, null, TEST_ACCESS_TOKEN); // call apiFunc(...parameters); // verify expect(AuthorizationController.prototype.tokenRefreshAndRead.called).equal(true); expect(AuthorizationController.prototype.tokenRefreshAndRead.args[0][0]).equal(TEST_PROFILE); expect(httpClientStub.args[0][0]).deep.equal(expectedOptions); done(); }); }); afterEach(() => { sinon.restore(); }); }); };