Skip to content

Commit

Permalink
fix: buttons and add test on button
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed Aug 14, 2018
1 parent 019ad4d commit 3740b40
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lint": "eslint src",
"test": "jest",
"dev": "tsc -w --declaration",
"build": "rm -rf dist && tsc --declaration; cp -r ./src/types ./dist/types",
"build": "rm -rf dist && tsc --declaration",
"version": "npm run changelog && git add CHANGELOG.md",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"release": "conventional-github-releaser -p angular",
Expand Down
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ export {

import { Alice } from './alice';

/**
* For compability with commonjs
* @example const Alice = require('yandex-dialogs-sdk')
*/
module.exports = Alice;
exports = module.exports;

export default Alice;

export { Reply } from './reply/reply';
export { Markup } from './reply/markup';

Expand All @@ -43,3 +34,5 @@ export {
export { Alice, IAlice } from './alice';
export { IContext } from './context';
export { IImagesApi } from './imagesApi';

export default Alice;
8 changes: 7 additions & 1 deletion src/reply/extraParamsBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IApiResponseBodyButton } from '../api/response';
import { BodyButtonDeclaration } from './bodyButtonBuilder';
import { BodyButtonBuilder } from './bodyButtonBuilder';

export interface IExtraParams {
tts?: string;
buttons?: IApiResponseBodyButton[];
end_session?: boolean;
end_session: boolean;
}

export interface IExtraParamsReply {
Expand All @@ -21,6 +22,11 @@ export class ExtraParamsBuilder {
): IExtraParams {
if (typeof declaration === 'object') {
return {
buttons:
declaration.buttons &&
declaration.buttons.map(button =>
BodyButtonBuilder.createBodyButton(button),
),
end_session: Boolean(declaration.end_session),
tts: declaration.tts,
};
Expand Down
1 change: 0 additions & 1 deletion src/stage/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export class Stage implements IStage {
enter: (name: string) => compere.enter(name),
leave: () => compere.leave(),
};
debug(`current scene "${scene.name}"`);
const result = await scene.run(stageContext);
return {
responseBody: result,
Expand Down
14 changes: 8 additions & 6 deletions tests/reply.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Reply, Markup } from '../dist';
import { getRandomText } from './testUtils';

const M = Markup;
describe('Alice Reply (static method) suite', () => {
let text = '';
beforeEach(() => {
Expand All @@ -18,14 +19,15 @@ describe('Alice Reply (static method) suite', () => {
text: text,
tts: `${text}+`,
end_session: true,
buttons: [M.button('one'), M.button('two'), M.button('three')],
};
expect(
Reply.text(expected.text, { tts: expected.tts, end_session: true }),
).toEqual({
text: text,
tts: expected.tts,
end_session: true,
});
Reply.text(expected.text, {
tts: expected.tts,
end_session: true,
buttons: ['one', 'two', 'three'],
}),
).toEqual(expected);
});
test('BigImage Card reply', () => {
const expected = {
Expand Down

0 comments on commit 3740b40

Please sign in to comment.