Add some integration testing of the /events service just to sanity check myself

This commit is contained in:
R. Tyler Croy 2018-09-10 10:02:36 -07:00
parent 1d9999aa59
commit b7f080d25a
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
3 changed files with 59 additions and 7 deletions

View File

@ -13,8 +13,8 @@ depends: package.json package-lock.json
build: depends
tsc
check: depends
jest
check: build depends migrate
jest --bail
clean:
$(COMPOSE) down || true
@ -28,13 +28,16 @@ debug-db:
migrate: depends
$(COMPOSE) up -d db
@echo ">> waiting a bit to make sure the database comes online.."
@sleep 5
@echo ">> waiting a moment to make sure the database comes online.."
@sleep 1
$(COMPOSE) run --rm node \
/usr/local/bin/node ./node_modules/.bin/sequelize db:migrate
watch:
jest --watchAll
watch: migrate
# Running with docker-compose since our tests require a database to be
# present
$(COMPOSE) run --rm node \
/usr/local/bin/node ./node_modules/.bin/jest --watchAll --bail
watch-compile:
tsc -w

View File

@ -22,5 +22,5 @@ curl -d '{"type":"stapler", "correlator" : "my-correlator-id", "payload" : {"hi"
[source,bash]
----
./tools/docker-compose run --rm db psql -h db -U postgres uplink_development
make debug-db
----

49
test/events.test.ts Normal file
View File

@ -0,0 +1,49 @@
import url from 'url';
import request from 'request-promise';
import app from '../src/app';
// Offsetting a bit to ensure that we can watch and run at the same time
const port = (app.get('port') || 3030) + 10;
const getUrl = pathname => url.format({
hostname: app.get('host') || 'localhost',
protocol: 'http',
port,
pathname
});
describe('Acceptance tests for /evetns', () => {
beforeEach((done) => {
this.server = app.listen(port);
this.server.once('listening', () => done());
});
afterEach((done) => {
this.server.close(done);
});
it('responds to GET /events', () => {
return request(getUrl('/events'), {
json: true,
resolveWithFullResponse: true,
}).then(response =>
expect(response.statusCode).toEqual(200)
);
});
it('POST /events should allow creating a valid event', () => {
return request(getUrl('/events'), {
json: true,
resolveWithFullResponse: true,
body: {
type: 'jest-example',
payload: {
generatedAt: Date.now(),
},
correlator: '0xdeadbeef',
},
}).then(response =>
expect(response.statusCode).toEqual(200)
);
});
});