Skip to content
Merged
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
2 changes: 2 additions & 0 deletions config/param-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
body: {
clientId: Joi.string().required(),
deviceType: Joi.string().required().valid(['iOS', 'Android', 'Browser', 'API']),
eventApiEnv: Joi.string().required().valid(['production', 'test']),
eventTime: Joi.date().timestamp('unix').required(),
eventData: Joi.object().required(),
eventType: Joi.string().required().valid([
Expand All @@ -26,6 +27,7 @@ export default {
body: {
clientId: Joi.string().required(),
deviceType: Joi.string().required().valid(['iOS', 'Android', 'Browser', 'API']),
eventApiEnv: Joi.string().required().valid(['production', 'test']),
errorTime: Joi.date().timestamp('unix').required(),
errorData: Joi.object().required(),
}
Expand Down
48 changes: 48 additions & 0 deletions tests/server/errors/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('## Basic Error APIs', () => {
it('sending valid error is successful', (done) => {
const error = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'API',
errorTime: new Date().getTime(),
errorData: {
Expand All @@ -30,6 +31,7 @@ describe('## Basic Error APIs', () => {
it('errors when no clientId is sent', (done) => {
const error = {
deviceType: 'Browser',
eventApiEnv: 'production',
errorTime: new Date().getTime(),
errorData: {}
};
Expand All @@ -48,6 +50,7 @@ describe('## Basic Error APIs', () => {
it('errors when no deviceType is sent', (done) => {
const error = {
clientId: '1234567',
eventApiEnv: 'production',
errorTime: new Date().getTime(),
errorData: {
userId: '3462562'
Expand All @@ -68,6 +71,7 @@ describe('## Basic Error APIs', () => {
it('errors when no errorTime is sent', (done) => {
const error = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'API',
errorData: {
userId: '3462562'
Expand All @@ -88,6 +92,7 @@ describe('## Basic Error APIs', () => {
it('errors when no errorData is sent', (done) => {
const error = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'API',
errorTime: new Date().getTime()
};
Expand All @@ -102,4 +107,47 @@ describe('## Basic Error APIs', () => {
})
.catch(done);
});

it('errors when no eventApiEnv is sent', (done) => {
const error = {
clientId: '1234567',
errorData: {
userId: '3462562'
},
deviceType: 'API',
errorTime: new Date().getTime()
};
request(app)
.post('/api/v1/error')
.send(error)
.expect(httpStatus.BAD_REQUEST)
.then((res) => {
expect(res.body).to.exist; //eslint-disable-line
expect(res.body.message).to.equal('"eventApiEnv" is required')
done();
})
.catch(done);
});

it('errors when eventApiEnv sent is wrong type', (done) => {
const error = {
clientId: '1234567',
eventApiEnv: 'prod',
errorData: {
userId: '3462562'
},
deviceType: 'API',
errorTime: new Date().getTime()
};
request(app)
.post('/api/v1/error')
.send(error)
.expect(httpStatus.BAD_REQUEST)
.then((res) => {
expect(res.body).to.exist; //eslint-disable-line
expect(res.body.message).to.equal('"eventApiEnv" must be one of [production, test]'); //eslint-disable-line
done();
})
.catch(done);
});
});
55 changes: 54 additions & 1 deletion tests/server/events/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('## Basic Event APIs', () => {
it('sending valid event is successful', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'test',
deviceType: 'iOS',
eventTime: new Date().getTime(),
eventType: 'login',
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('## Basic Event APIs', () => {
it('errors with invalid deviceType', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'Windows phone',
eventTime: new Date().getTime(),
eventType: 'login',
Expand All @@ -62,6 +64,7 @@ describe('## Basic Event APIs', () => {
it('errors with invalid timestamp', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'Browser',
eventTime: new Date(),
eventType: 'login',
Expand Down Expand Up @@ -89,7 +92,7 @@ describe('## Basic Event APIs', () => {
.expect(httpStatus.BAD_REQUEST)
.then((res) => {
expect(res.body).to.exist; //eslint-disable-line
expect(res.body.message).to.equal('"clientId" is required and "deviceType" is required and "eventTime" is required and "eventData" is required and "eventType" is required'); //eslint-disable-line
expect(res.body.message).to.equal('"clientId" is required and "deviceType" is required and "eventApiEnv" is required and "eventTime" is required and "eventData" is required and "eventType" is required'); //eslint-disable-line
done();
})
.catch(done);
Expand All @@ -98,6 +101,7 @@ describe('## Basic Event APIs', () => {
it('errors when no clientId sent', (done) => {
const event = {
deviceType: 'Browser',
eventApiEnv: 'production',
eventTime: new Date().getTime(),
eventType: 'login',
eventData: {
Expand All @@ -119,6 +123,7 @@ describe('## Basic Event APIs', () => {
it('errors when no deviceType sent', (done) => {
const event = {
clientId: '45426562',
eventApiEnv: 'production',
eventTime: new Date().getTime(),
eventType: 'login',
eventData: {
Expand All @@ -140,6 +145,7 @@ describe('## Basic Event APIs', () => {
it('errors when no eventData sent', (done) => {
const event = {
clientId: '45426562',
eventApiEnv: 'production',
deviceType: 'API',
eventTime: new Date().getTime(),
eventType: 'login'
Expand All @@ -159,6 +165,7 @@ describe('## Basic Event APIs', () => {
it('errors when no eventType sent', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'Android',
eventTime: new Date().getTime(),
eventData: {
Expand All @@ -180,6 +187,7 @@ describe('## Basic Event APIs', () => {
it('errors when no eventTime sent', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'iOS',
eventType: 'login',
eventData: {
Expand All @@ -197,4 +205,49 @@ describe('## Basic Event APIs', () => {
})
.catch(done);
});

it('errors when no eventApiEnv sent', (done) => {
const event = {
clientId: '1234567',
deviceType: 'iOS',
eventTime: new Date().getTime(),
eventType: 'login',
eventData: {
userId: '8675309'
}
}
request(app)
.post('/api/v1/event')
.send(event)
.expect(httpStatus.BAD_REQUEST)
.then((res) => {
expect(res.body).to.exist; //eslint-disable-line
expect(res.body.message).to.equal('"eventApiEnv" is required'); //eslint-disable-line
done();
})
.catch(done);
});

it('errors when eventApiEnv sent is wrong type', (done) => {
const event = {
clientId: '1234567',
deviceType: 'iOS',
eventApiEnv: 'testing',
eventTime: new Date().getTime(),
eventType: 'login',
eventData: {
userId: '8675309'
}
}
request(app)
.post('/api/v1/event')
.send(event)
.expect(httpStatus.BAD_REQUEST)
.then((res) => {
expect(res.body).to.exist; //eslint-disable-line
expect(res.body.message).to.equal('"eventApiEnv" must be one of [production, test]'); //eslint-disable-line
done();
})
.catch(done);
});
});
1 change: 1 addition & 0 deletions tests/server/events/register.event.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('## Register Events', () => {
it('sending valid register event is successful', (done) => {
const event = {
clientId: '1234567',
eventApiEnv: 'production',
deviceType: 'Android',
eventTime: new Date().getTime(),
eventType: 'register',
Expand Down