-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: tests codestyle, remove redundant
- Loading branch information
fletcherist
committed
Aug 12, 2018
1 parent
bcb49ac
commit 42568eb
Showing
4 changed files
with
68 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
module.exports = { | ||
"roots": [ | ||
"<rootDir>/src" | ||
], | ||
"transform": { | ||
"^.+\\.tsx?$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"tsx", | ||
"js", | ||
"jsx", | ||
"json", | ||
"node" | ||
], | ||
} | ||
roots: ['<rootDir>/tests'], | ||
testURL: 'http://localhost/', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,87 @@ | ||
import Alice from '../alice' | ||
import { generateRequest } from './testUtils' | ||
import { Alice } from '../src/alice'; | ||
import { generateRequest } from './testUtils'; | ||
|
||
// Test for matching all command types | ||
|
||
test('matching with string', async done => { | ||
const alice = new Alice() | ||
const alice = new Alice(); | ||
|
||
alice.command('Привет, как дела', ctx => done()) | ||
alice.handleRequest(generateRequest('Привет, как дела?')) | ||
}) | ||
alice.command('Привет, как дела', ctx => done()); | ||
alice.handleRequest(generateRequest('Привет, как дела?')); | ||
}); | ||
|
||
test('matching with array', async done => { | ||
const alice = new Alice() | ||
const alice = new Alice(); | ||
|
||
alice.command(['привет', 'как дела'], ctx => done()) | ||
alice.handleRequest(generateRequest('Привет, как дела?')) | ||
}) | ||
alice.command(['привет', 'как дела'], ctx => done()); | ||
alice.handleRequest(generateRequest('Привет, как дела?')); | ||
}); | ||
|
||
test('matching with regexp', async done => { | ||
const alice = new Alice() | ||
const alice = new Alice(); | ||
|
||
alice.command(/[а-яё]+/i, ctx => done()) | ||
alice.any(ctx => ctx) | ||
alice.handleRequest(generateRequest('Привет как дела')) | ||
}) | ||
alice.command(/[а-яё]+/i, ctx => done()); | ||
alice.any(ctx => ctx); | ||
alice.handleRequest(generateRequest('Привет как дела')); | ||
}); | ||
|
||
test('priority check, strings over regexps', async done => { | ||
const alice = new Alice() | ||
const alice = new Alice(); | ||
|
||
alice.command(/[а-яё]+/i, ctx => new Error('Error has occured')) | ||
alice.command('привет', ctx => done()) | ||
alice.any(ctx => ctx) | ||
alice.handleRequest(generateRequest('Привет как дела')) | ||
}) | ||
alice.command(/[а-яё]+/i, ctx => new Error('Error has occured')); | ||
alice.command('привет', ctx => done()); | ||
alice.any(ctx => ctx); | ||
alice.handleRequest(generateRequest('Привет как дела')); | ||
}); | ||
|
||
test('listenining on port with callback', async done => { | ||
const alice = new Alice() | ||
alice.listen('/', 3000, () => { | ||
alice.stopListening() | ||
done() | ||
}) | ||
}) | ||
const alice = new Alice(); | ||
alice.listen('/', 3000, () => { | ||
alice.stopListening(); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('listening on port with promise', async done => { | ||
const alice = new Alice() | ||
alice.listen('/', 3000).then(() => { | ||
alice.stopListening() | ||
done() | ||
}) | ||
}) | ||
const alice = new Alice(); | ||
alice.listen('/', 3000).then(() => { | ||
alice.stopListening(); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('ctx body', async done => { | ||
const alice = new Alice() | ||
alice.command('забронируй встречу в ${where} на ${when}', ctx => { | ||
/* | ||
const alice = new Alice(); | ||
alice.command('забронируй встречу в ${where} на ${when}', ctx => { | ||
/* | ||
* Context body parses message and extract phrases | ||
* in brackets! | ||
*/ | ||
expect(ctx.body).toEqual({ | ||
where: '7-холмов', | ||
when: '18:00', | ||
}) | ||
done() | ||
}) | ||
alice.handleRequest(generateRequest('забронируй встречу в 7-холмов на 18:00')) | ||
}) | ||
expect(ctx.body).toEqual({ | ||
where: '7-холмов', | ||
when: '18:00', | ||
}); | ||
done(); | ||
}); | ||
alice.handleRequest( | ||
generateRequest('забронируй встречу в 7-холмов на 18:00'), | ||
); | ||
}); | ||
|
||
test('handling command resolve with callback', async done => { | ||
const alice = new Alice() | ||
const MOCK_MSG = 'Hello world' | ||
alice.any(ctx => ctx.reply(MOCK_MSG)) | ||
alice.handleRequest(generateRequest('hi!'), response => { | ||
expect(response.response.text).toBe(MOCK_MSG) | ||
done() | ||
}) | ||
}) | ||
const alice = new Alice(); | ||
const MOCK_MSG = 'Hello world'; | ||
alice.any(ctx => ctx.reply(MOCK_MSG)); | ||
alice.handleRequest(generateRequest('hi!'), response => { | ||
expect(response.response.text).toBe(MOCK_MSG); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('handling command resolve with promise', async () => { | ||
const alice = new Alice() | ||
const MOCK_MSG = 'Hello world' | ||
alice.any(ctx => ctx.reply(MOCK_MSG)) | ||
const response = await alice.handleRequest(generateRequest('hi!')) | ||
expect(response.response.text).toBe(MOCK_MSG) | ||
}) | ||
const alice = new Alice(); | ||
const MOCK_MSG = 'Hello world'; | ||
alice.any(ctx => ctx.reply(MOCK_MSG)); | ||
const response = await alice.handleRequest(generateRequest('hi!')); | ||
expect(response.response.text).toBe(MOCK_MSG); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,3 @@ export const generateRequest = ( | |
}, | ||
version: '1.0', | ||
}); | ||
|
||
module.exports.generateRequest = generateRequest; |