Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
dist/
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "6river/typescript"
"extends": "6river/typescript",
"parser": "@typescript-eslint/parser"
}
68 changes: 34 additions & 34 deletions e2e/component.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
let should = require('chai').should();
let app = require('./server');
let request = require('supertest');
var spy = require('sinon').spy;
let stream = require('stream');
let http = require('http');
let uuid = require('uuid');
const should = require('chai').should();
const app = require('./server');
const request = require('supertest');
const spy = require('sinon').spy;
const stream = require('stream');
const http = require('http');
const uuid = require('uuid');

describe('loopback-component-changestreamer', () => {

let Foo;
let Bar;

Expand All @@ -21,9 +20,10 @@ describe('loopback-component-changestreamer', () => {

changesUrl = app.settings.url + 'changes';
messages = [];
// eslint-disable-next-line
outStream = stream.PassThrough();
outStream.on('data', (chunk) => {
let textChunk = chunk.toString('utf8');
const textChunk = chunk.toString('utf8');
messages.push(textChunk);
});
});
Expand All @@ -35,27 +35,28 @@ describe('loopback-component-changestreamer', () => {
context('initialize connection', () => {
it('should set SSE headers', (done) => {
request(app).get('/changes')
.expect('Content-Type', /text\/event-stream/)
.expect('Connection', 'keep-alive')
.expect('Cache-Control', 'no-cache')
.expect('Access-Control-Allow-Origin', '*')
.expect(200, done);
.expect('Content-Type', /text\/event-stream/)
.expect('Connection', 'keep-alive')
.expect('Cache-Control', 'no-cache')
.expect('Access-Control-Allow-Origin', '*')
.expect(200, done);
});

it('set user headers', (done) => {
const fooID = uuid.v4();
let foo = {id: fooID, foo: 'habba'};
const foo = {id: fooID, foo: 'habba'};
http.get(changesUrl, (res) => {
res.pipe(outStream);
});
request(app).post('/api/Foos')
.set('X-Auth-Request-User','test@gmail.com')
.send(foo)
.expect(200)
.then(response => {
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","meta":{"headers":{"x-auth-request-user":"test@gmail.com"}},"data":{"id":"${fooID}","foo":"habba"}}\n\n`);
done();
});
.set('X-Auth-Request-User', 'test@gmail.com')
.send(foo)
.expect(200)
.then((response) => {
// eslint-disable-next-line
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","meta":{"headers":{"x-auth-request-user":"test@gmail.com"}},"data":{"id":"${fooID}","foo":"habba"}}\n\n`);
done();
});
});

it('should write retry timout as first parameter', (done) => {
Expand All @@ -79,33 +80,32 @@ describe('loopback-component-changestreamer', () => {
// create a model
Foo.create({id: fooID, foo: 'habba'});
// makes another model using new/save
let bar = new Bar({id: barID, bar: 'bahha'});
const bar = new Bar({id: barID, bar: 'bahha'});
bar.save();
});
setTimeout(() => {
messages.length.should.be.equal(3);
// eslint-disable-next-line
messages[1].should.equal(`data: {"seqNo":0,"modelName":"Foo","kind":"create","target":"${fooID}","meta":{"headers":[]},"data":{"id":"${fooID}","foo":"habba"}}\n\n`);
// eslint-disable-next-line
messages[2].should.equal(`data: {"seqNo":1,"modelName":"Bar","kind":"create","target":"${barID}","meta":{"headers":[]},"data":{"id":"${barID}","bar":"bahha"}}\n\n`);
done();
}, 2000);
});
});

context('statistics', () => {

it('should print statistics', (done) => {
request(app).get('/changes/stat')
.expect('Content-Type', /application\/json/)
.expect(200, {
connections: 0,
seqNo: 0
}, done);
.expect('Content-Type', /application\/json/)
.expect(200, {
connections: 0,
seqNo: 0,
}, done);
});

});

context('with existing models', () => {

let fooID;
let barID;
let foo;
Expand All @@ -130,6 +130,7 @@ describe('loopback-component-changestreamer', () => {
});
setTimeout(() => {
messages.length.should.be.equal(2);
// eslint-disable-next-line
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Foo","kind":"update","target":"${fooID}","meta":{"headers":[]},"data":{"id":"${fooID}","foo":"baz"}}\n\n`);
done();
}, 2000);
Expand All @@ -140,16 +141,15 @@ describe('loopback-component-changestreamer', () => {
it('should write change event with kind = remove', (done) => {
http.get(changesUrl, (res) => {
res.pipe(outStream);
bar.destroy()
bar.destroy();
});
setTimeout(() => {
messages.length.should.be.equal(2);
// eslint-disable-next-line
messages[1].should.equal(`data: {"seqNo":2,"modelName":"Bar","kind":"remove","target":"${barID}","where":{"id":"${barID}"},"meta":{"headers":[]},"data":{"id":"${barID}","bar":"bar"}}\n\n`);
done();
}, 2000);
});
});
});


});
6 changes: 2 additions & 4 deletions e2e/helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

let chai = require('chai');
let sinonChai = require('sinon-chai');
const chai = require('chai');
const sinonChai = require('sinon-chai');

chai.use(sinonChai);
4 changes: 1 addition & 3 deletions e2e/models/bar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
'use strict';

module.exports = function(Bar) {
}
};
4 changes: 1 addition & 3 deletions e2e/models/foo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
'use strict';

module.exports = function(Foo) {
}
};
12 changes: 7 additions & 5 deletions e2e/server.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
let loopback = require('loopback');
let boot = require('loopback-boot');
const loopback = require('loopback');
const boot = require('loopback-boot');

let app = module.exports = loopback();
const app = module.exports = loopback();

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) { throw err; }
if (err) {
throw err;
}
});

app.start = (done) => {
let listener = app.listen(() => {
const listener = app.listen(() => {
app.stop = function(cb) {
listener.close(cb);
};
Expand Down
9 changes: 0 additions & 9 deletions gulpfile.js

This file was deleted.

Loading