Skip to content

Commit

Permalink
fix: typos in tests, ctx and main
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed Jul 1, 2018
1 parent ff44115 commit 0c55743
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 56 deletions.
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions src/alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class Alice {
}

/* @TODO: Implement watchers (errors, messages) */
// tslint:disable-next-line:no-empty
public on() {

}
Expand Down
9 changes: 5 additions & 4 deletions src/button.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const button = params => {
const button = (params) => {
// Button has been created from string
if (typeof params === 'string') {
return {
title: params
title: params,
}
}

Expand All @@ -13,7 +13,7 @@ const button = params => {
tts,
url,
hide = false,
payload
payload,
} = params

if (!title && !text) {
Expand All @@ -25,7 +25,7 @@ const button = params => {
tts,
url,
hide,
payload
payload,
}
}

Expand All @@ -34,3 +34,4 @@ const button = params => {
}

module.exports = button
export default button
25 changes: 18 additions & 7 deletions src/buttonBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@

interface ButtonConstructor {
title?: string // title and text — same
text?: string
}
export default class ButtonBuilder {
constructor(buttonConstructor?: {}) {
public button: {
title?: string,
url?: string,
hide?: boolean,
payload?: {},
}
constructor(buttonConstructor?: ButtonConstructor) {
/* No button object passed to the constructor */
if (!buttonConstructor) {
this.button = {}
Expand All @@ -17,15 +28,10 @@ export default class ButtonBuilder {
throw new Error('Button [title] or [text] is required for ButtonBuilder constructor.')
}

this.button = Object.assign({}, buttonConstructor)
this.button = buttonConstructor
return this.button
}

public _setTitle(title) {
this.button.title = title
return this
}

public text(text) {
return this._setTitle(text)
}
Expand All @@ -52,6 +58,11 @@ export default class ButtonBuilder {
public get() {
return this.button
}

private _setTitle(title) {
this.button.title = title
return this
}
}

module.exports = ButtonBuilder
8 changes: 0 additions & 8 deletions src/tests/.eslintrc.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/tests/button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const button = require('../button')

import button from '../button'

test('create button with string constructor', () => {
const expected = {
title: 'send message'
title: 'send message',
}
const btn = button(expected.title)
expect(btn).toEqual(expected)
Expand All @@ -12,12 +13,12 @@ test('create button with object constructor', () => {
const expected = {
title: 'show messages',
payload: { test: 'test' },
hide: true
hide: true,
}
const btn = button({
title: expected.title,
payload: expected.payload,
hide: expected.hide
hide: expected.hide,
})
expect(btn).toEqual(expected)
})
4 changes: 2 additions & 2 deletions src/tests/buttonBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ test('common test for buttonBuilder', () => {
url: 'https://example.com',
hide: true,
payload: {
some: 'data'
}
some: 'data',
},
}

const button = new ButtonBuilder()
Expand Down
16 changes: 8 additions & 8 deletions src/tests/reply.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const reply = require('../reply')
const {
import {
ALICE_PROTOCOL_VERSION,
DEFAULT_END_SESSION
} = require('../constants')
DEFAULT_END_SESSION,
} from '../constants'

test('create reply with string constructor', () => {
const expectedData = {
response: {
text: 'send message',
buttons: [],
end_session: DEFAULT_END_SESSION
end_session: DEFAULT_END_SESSION,
},
session: null,
version: ALICE_PROTOCOL_VERSION
version: ALICE_PROTOCOL_VERSION,
}

const msg = reply(expectedData.response.text)
Expand All @@ -25,17 +25,17 @@ test('create reply with object constructor', () => {
text: 'send message',
tts: 'send m+essage',
buttons: [],
end_session: true
end_session: true,
},
session: null,
version: ALICE_PROTOCOL_VERSION
version: ALICE_PROTOCOL_VERSION,
}

const msg = reply({
text: expectedData.response.text,
tts: expectedData.response.tts,
buttons: expectedData.response.buttons,
endSession: expectedData.response.end_session
endSession: expectedData.response.end_session,
})
expect(msg).toEqual(expectedData)
})
4 changes: 2 additions & 2 deletions src/tests/reversedInterpolation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { reversedInterpolation } = require('../utils')

test('interpolation execution', () => {
const template = 'Alice, i want to by ${what} for ${price} and'
const string = 'Alice, i want to by Apple for smth and'
const searchString = 'Alice, i want to by Apple for smth and'
const expected = { what: 'Apple', price: 'smth' }
expect(reversedInterpolation(template, string)).toEqual(expected)
expect(reversedInterpolation(template, searchString)).toEqual(expected)
})

0 comments on commit 0c55743

Please sign in to comment.