jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 309 forks source link

Be able to add mock accessToken to request body in test #207

Closed VinozzZ closed 6 years ago

VinozzZ commented 6 years ago

I'm submitting a...

Expected Behavior

I would like to be able to add my mock accessToken to my request before send().

Current Behavior

/* global describe, it */

const { expect } = require('chai');
const { getPlatformRequestBuilder } = require('jovo-framework').util;
const { set } = require('lodash');
const { send } = require('jovo-framework').TestSuite;
const { HELP_MESSAGE } = require('../dist/constants/default_messages');
const COMMAND_RESPONSES = require('../dist/constants/command_responses');

const rb = getPlatformRequestBuilder('GoogleActionDialogFlowV2')[0];
const testToken = 123456;

describe('LAUNCH', () => {
  it('should return a message asking for users to link their ergo account', () => {
    const requestWithToken = rb.launch();
    set(requestWithToken, 'originalDetectIntentRequest.payload.user.accessToken', testToken);
    return send(rb.intent(requestWithToken))
      .then((res) => {
        const matchResponse = res.isAsk(HELP_MESSAGE);
        expect(matchResponse).to.equal(true);
      });
  });

  it('should return a message asking for users to give commands', () => {
    const requestWithToken = rb.intent('RaiseHeadIntent');
    set(requestWithToken, 'originalDetectIntentRequest.payload.user.accessToken', testToken);
    return send(requestWithToken.setSessionAttribute())
      .then((res) => {
        const matchResponse = res.isAsk(COMMAND_RESPONSES[8] + HELP_MESSAGE);
        expect(matchResponse).to.equal(true);
      });
  });
});

Your Environment

aswetlow commented 6 years ago

Hey @VinozzZ! We just added the setAccessToken(token) method to the request class. Please update to v1.3.5

rb.intent('RaiseHeadIntent').setAccessToken(token)
VinozzZ commented 6 years ago

@aswetlow I would love to help to update the doc for this if you guys need

aswetlow commented 6 years ago

That would be awesome. Thanks!