Skip to content

Commit

Permalink
add consumer service test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kylie Pace committed Jan 18, 2021
1 parent 565bb48 commit 8639ebf
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
"compile": "rm -Rf ./lib && tsc",
"consumer:dev": "ts-node-dev src/consumer/app.ts",
"lint": "eslint --ext .js,.ts src/",
"mocha": "ts-mocha \"test/**/*.ts\" --recursive --exit",
"server:dev": "ts-node-dev src/server/index.ts",
"start": "npm run lib/index.js",
"test": "NODE_ENV=test npm run mocha"
"test:consumer": "ts-mocha \"test/consumer/**/**.ts\" --recursive --exit",
"test:integration": "NODE_ENV=test ts-mocha \"test/websocket.test.ts\" --recursive --exit",
"test": "npm run test:consumer && npm run test:integration"
},
"author": "Kylie Pace",
"license": "ISC",
Expand Down
99 changes: 99 additions & 0 deletions test/consumer/services/TransformService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import chai from 'chai';
import TransformService from '../../../src/consumer/services/TransformService';


describe('consumer > services > transformService', () => {
let transformService = new TransformService();
describe('#buildChildData', () => {
describe('data without SESSION_START or SESSION_END events', () => {
let childData;
before(() => {
const data = [
{
timestamp: 1569972083,
type: 'EVENT',
name: 'cart_loaded'
}
];
childData = transformService.buildChildData(data);
});
it('returns all the input data', () => {
chai.expect(childData.length).to.equal(1);
});
});

describe('data with SESSION_START event', () => {
let childData;
before(() => {
const data = [
{
timestamp: 1569972083,
type: 'SESSION_START',
session_id: '12'
},
{
timestamp: 1569972083,
type: 'EVENT',
name: 'cart_loaded'
}
];
childData = transformService.buildChildData(data, data[0].timestamp);
});
it('returns all the input data minus the first event', () => {
chai.expect(childData.length).to.equal(1);
chai.expect(childData[0].name).to.equal('cart_loaded');
});
});

describe('data with SESSION_END event', () => {
let childData;
before(() => {
const data = [
{
timestamp: 1569972083,
type: 'EVENT',
name: 'cart_loaded'
},
{
timestamp: 1569972083,
type: 'SESSION_END',
session_id: '12'
},
];
childData = transformService.buildChildData(data, undefined, data[1].timestamp);
});
it('returns all the input data minus the last event', () => {
chai.expect(childData.length).to.equal(1);
chai.expect(childData[0].name).to.equal('cart_loaded');
});
});

describe('data with SESSION_START and SESSION_END event', () => {
let childData;
before(() => {
const data = [
{
timestamp: 1569972083,
type: 'SESSION_START',
session_id: '12'
},
{
timestamp: 1569972083,
type: 'EVENT',
name: 'cart_loaded'
},
{
timestamp: 1569972083,
type: 'SESSION_END',
session_id: '12'
},
];
childData = transformService.buildChildData(data, data[0].timestamp, data[2].timestamp);
});
it('returns all the input data minus the last event', () => {
chai.expect(childData.length).to.equal(1);
chai.expect(childData[0].name).to.equal('cart_loaded');
});
});
});
});

0 comments on commit 8639ebf

Please sign in to comment.