204 lines
5.5 KiB
JavaScript
204 lines
5.5 KiB
JavaScript
/**
|
|
* @fileOverview Unit tests for the schemas for the message commands
|
|
* @see {@url http://10.0.10.242/w/tricore_architecture/server_interface/message_commands/}
|
|
*/
|
|
var _ = require('lodash');
|
|
var testHelper = require('./testHelpers.js');
|
|
|
|
/**
|
|
* Test data
|
|
*/
|
|
const VALID_SESSION_TOKEN = '01234567890abcdefghijklmnopqrstuvwxyzABCDE';
|
|
const VALID_DEVICE_TOKEN = '01234567890abcdefghijklmnopqrstuvwxyzABCDE';
|
|
const VALID_UUID = '0123456789abcdef01234567';
|
|
|
|
/**
|
|
* Test suite that defines the test command body and expected outcomes for
|
|
* a range of different bodies across different commands.
|
|
*/
|
|
const TEST_SUITE = {
|
|
DeleteMessage: [
|
|
{
|
|
name: '',
|
|
valid: true,
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: VALID_UUID
|
|
}
|
|
},
|
|
{
|
|
name: 'no params',
|
|
valid: false,
|
|
expect: {
|
|
missingRequiredCount: 3,
|
|
additionalPropsCount: 1
|
|
},
|
|
data: {invalidAdditionalProp: 'a'}
|
|
},
|
|
{
|
|
name: 'mistake in every param',
|
|
valid: false,
|
|
expect: {
|
|
errors: [
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'minLength'
|
|
},
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'pattern'
|
|
}
|
|
]
|
|
},
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: 'Not a UUID'
|
|
}
|
|
}
|
|
],
|
|
GetMessage: [
|
|
{
|
|
name: '',
|
|
valid: true,
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: VALID_UUID
|
|
}
|
|
},
|
|
{
|
|
name: 'no params',
|
|
valid: false,
|
|
expect: {
|
|
missingRequiredCount: 3,
|
|
additionalPropsCount: 1
|
|
},
|
|
data: {invalidAdditionalProp: 'a'}
|
|
},
|
|
{
|
|
name: 'mistake in every param',
|
|
valid: false,
|
|
expect: {
|
|
errors: [
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'minLength'
|
|
},
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'pattern'
|
|
}
|
|
]
|
|
},
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: 'Not a UUID'
|
|
}
|
|
}
|
|
],
|
|
ListMessages: [
|
|
{
|
|
name: '',
|
|
valid: true,
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
Skip: 9999,
|
|
Number: 30,
|
|
Type: 'Login'
|
|
}
|
|
},
|
|
{
|
|
name: 'missing required params',
|
|
valid: false,
|
|
expect: {
|
|
missingRequiredCount: 2,
|
|
additionalPropsCount: 1
|
|
},
|
|
data: {invalidAdditionalProp: 'a'}
|
|
},
|
|
{
|
|
name: 'mistake in every param',
|
|
valid: false,
|
|
expect: {
|
|
errors: [
|
|
{
|
|
dataPath: '.Skip',
|
|
keyword: 'minimum'
|
|
},
|
|
{
|
|
dataPath: '.Number',
|
|
keyword: 'maximum'
|
|
},
|
|
{
|
|
dataPath: '.Type',
|
|
keyword: 'enum'
|
|
}
|
|
]
|
|
},
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
Skip: -1,
|
|
Number: 31,
|
|
Type: 'All'
|
|
}
|
|
}
|
|
],
|
|
MarkMessage: [
|
|
{
|
|
name: '',
|
|
valid: true,
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: VALID_UUID,
|
|
Mark: 'Unread'
|
|
}
|
|
},
|
|
{
|
|
name: 'no params',
|
|
valid: false,
|
|
expect: {
|
|
missingRequiredCount: 4,
|
|
additionalPropsCount: 1
|
|
},
|
|
data: {invalidAdditionalProp: 'a'}
|
|
},
|
|
{
|
|
name: 'mistake in every param',
|
|
valid: false,
|
|
expect: {
|
|
errors: [
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'minLength'
|
|
},
|
|
{
|
|
dataPath: '.MessageID',
|
|
keyword: 'pattern'
|
|
},
|
|
{
|
|
dataPath: '.Mark',
|
|
keyword: 'enum'
|
|
}
|
|
]
|
|
},
|
|
data: {
|
|
DeviceToken: VALID_DEVICE_TOKEN,
|
|
SessionToken: VALID_SESSION_TOKEN,
|
|
MessageID: 'Not a UUID',
|
|
Mark: 'Important'
|
|
}
|
|
}
|
|
]
|
|
};
|
|
|
|
/**
|
|
* Run the test suite through the test runner
|
|
*/
|
|
testHelper.runTestSuite('Schemas: Message Commands', TEST_SUITE);
|