Skip to content

Commit

Permalink
fix: tests codestyle, remove redundant
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed Aug 12, 2018
1 parent bcb49ac commit 42568eb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 117 deletions.
24 changes: 8 additions & 16 deletions jest.config.js
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'],
};
118 changes: 60 additions & 58 deletions tests/alice.spec.ts
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);
});
41 changes: 0 additions & 41 deletions tests/sessions.spec.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ export const generateRequest = (
},
version: '1.0',
});

module.exports.generateRequest = generateRequest;

0 comments on commit 42568eb

Please sign in to comment.