ask-cli
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
86 lines (79 loc) • 3.66 kB
JavaScript
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('# skill accountLinking APIs', () => {
let httpClientStub;
beforeEach(() => {
httpClientStub = sinon.stub(httpClient, 'request').callsFake(noop);
sinon.stub(AuthorizationController.prototype, 'tokenRefreshAndRead');
});
const TEST_SKILL_ID = 'skillId';
const TEST_SKILL_STAGE = 'skillStage';
const TEST_ACCOUNT_LINKING_INFO = 'accountLinkingInfo';
const TEST_PROFILE = 'testProfile';
const TEST_ACCESS_TOKEN = 'access_token';
[
{
testCase: 'get-account-linking',
apiFunc: smapiClient.skill.accountLinking.getAccountLinking,
parameters: [TEST_SKILL_ID, TEST_SKILL_STAGE, noop],
expectedOptions: {
url: `${CONSTANTS.SMAPI.ENDPOINT}/v1/skills/${TEST_SKILL_ID}/stages/${TEST_SKILL_STAGE}/accountLinkingClient`,
method: CONSTANTS.HTTP_REQUEST.VERB.GET,
headers: {
authorization: TEST_ACCESS_TOKEN
},
body: null,
json: false
}
},
{
testCase: 'set-account-linking',
apiFunc: smapiClient.skill.accountLinking.setAccountLinking,
parameters: [TEST_SKILL_ID, TEST_SKILL_STAGE, TEST_ACCOUNT_LINKING_INFO, noop],
expectedOptions: {
url: `${CONSTANTS.SMAPI.ENDPOINT}/v1/skills/${TEST_SKILL_ID}/stages/${TEST_SKILL_STAGE}/accountLinkingClient`,
method: CONSTANTS.HTTP_REQUEST.VERB.PUT,
headers: {
authorization: TEST_ACCESS_TOKEN
},
body: { accountLinkingRequest: TEST_ACCOUNT_LINKING_INFO },
json: true
}
},
{
testCase: 'delete-account-linking',
apiFunc: smapiClient.skill.accountLinking.deleteAccountLinking,
parameters: [TEST_SKILL_ID, TEST_SKILL_STAGE, noop],
expectedOptions: {
url: `${CONSTANTS.SMAPI.ENDPOINT}/v1/skills/${TEST_SKILL_ID}/stages/${TEST_SKILL_STAGE}/accountLinkingClient`,
method: CONSTANTS.HTTP_REQUEST.VERB.DELETE,
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();
});
});
};