Add some integration testing of the /events service just to sanity check myself
This commit is contained in:
parent
1d9999aa59
commit
b7f080d25a
15
Makefile
15
Makefile
|
@ -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
|
||||
|
|
|
@ -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
|
||||
----
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue