Skip to content

Commit

Permalink
Added tests to exercise bodytrack-datastore's new (as of v4.3.0) abil…
Browse files Browse the repository at this point in the history
…ity to detect invalid channel names upon import
  • Loading branch information
chrisbartley committed Mar 24, 2022
1 parent c05e131 commit 630eb35
Show file tree
Hide file tree
Showing 12 changed files with 372 additions and 4 deletions.
74 changes: 73 additions & 1 deletion test/api.feeds.upload.feed-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ describe("REST API", function() {
response : requireNew('./fixtures/feed-upload8-response.json')
};

const invalidChannelName1 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-1-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-1-response.json')
}

const invalidChannelName2 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-2-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-2-response.json')
}

const invalidChannelName3 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-3-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-3-response.json')
}

const invalidChannelName4 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-4-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-4-response.json')
}

before(function(initDone) {
flow.series(
[
Expand Down Expand Up @@ -312,9 +332,61 @@ describe("REST API", function() {
expectedHttpStatus : httpStatus.UNAUTHORIZED,
expectedStatusText : 'error',
hasEmptyBody : true
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : ESDR_FEED_API_URL,
headers : function() {
return {
FeedApiKey : feed1.apiKey
}
},
dataToUpload : invalidChannelName1.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName1.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : ESDR_FEED_API_URL,
headers : function() {
return {
FeedApiKey : feed1.apiKey
}
},
dataToUpload : invalidChannelName2.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName2.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : ESDR_FEED_API_URL,
headers : function() {
return {
FeedApiKey : feed1.apiKey
}
},
dataToUpload : invalidChannelName3.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName3.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : ESDR_FEED_API_URL,
headers : function() {
return {
FeedApiKey : feed1.apiKey
}
},
dataToUpload : invalidChannelName4.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName4.response,
}
].forEach(executeUploadTest);
}); // End To /feed method
}); // End Upload
}); // End Feeds
}); // End REST API
}); // End REST API
74 changes: 73 additions & 1 deletion test/api.feeds.upload.feeds-method.apikey-auth.request-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ describe("REST API", function() {
response : requireNew('./fixtures/feed-upload8-response.json')
};

const invalidChannelName1 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-1-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-1-response.json')
}

const invalidChannelName2 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-2-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-2-response.json')
}

const invalidChannelName3 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-3-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-3-response.json')
}

const invalidChannelName4 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-4-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-4-response.json')
}

before(function(initDone) {
flow.series(
[
Expand Down Expand Up @@ -370,6 +390,58 @@ describe("REST API", function() {
expectedHttpStatus : httpStatus.NOT_FOUND,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return { FeedApiKey : feed1.apiKey };
},
dataToUpload : invalidChannelName1.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName1.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return { FeedApiKey : feed1.apiKey };
},
dataToUpload : invalidChannelName2.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName2.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return { FeedApiKey : feed1.apiKey };
},
dataToUpload : invalidChannelName3.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName3.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return { FeedApiKey : feed1.apiKey };
},
dataToUpload : invalidChannelName4.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName4.response,
}
].forEach(executeUploadTest);

Expand All @@ -378,4 +450,4 @@ describe("REST API", function() {
}); // End To /feeds method
}); // End Upload
}); // End Feeds
}); // End REST API
}); // End REST API
62 changes: 61 additions & 1 deletion test/api.feeds.upload.feeds-method.apikey-auth.url.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ describe("REST API", function() {
response : requireNew('./fixtures/feed-upload8-response.json')
};

const invalidChannelName1 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-1-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-1-response.json')
}

const invalidChannelName2 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-2-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-2-response.json')
}

const invalidChannelName3 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-3-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-3-response.json')
}

const invalidChannelName4 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-4-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-4-response.json')
}

before(function(initDone) {
flow.series(
[
Expand Down Expand Up @@ -263,6 +283,46 @@ describe("REST API", function() {
expectedHttpStatus : httpStatus.NOT_FOUND,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName1.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName1.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName2.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName2.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName3.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName3.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.apiKey;
},
dataToUpload : invalidChannelName4.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName4.response,
}
].forEach(executeUploadTest);

Expand All @@ -271,4 +331,4 @@ describe("REST API", function() {
}); // End To /feeds method
}); // End Upload
}); // End Feeds
}); // End REST API
}); // End REST API
74 changes: 73 additions & 1 deletion test/api.feeds.upload.feeds-method.oauth2-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ describe("REST API", function() {
response : requireNew('./fixtures/feed-upload8-response.json')
};

const invalidChannelName1 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-1-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-1-response.json')
}

const invalidChannelName2 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-2-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-2-response.json')
}

const invalidChannelName3 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-3-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-3-response.json')
}

const invalidChannelName4 = {
request : requireNew('./fixtures/feed-upload-invalid-channel-name-4-request.json'),
response : requireNew('./fixtures/feed-upload-invalid-channel-name-4-response.json')
}

before(function(initDone) {
flow.series(
[
Expand Down Expand Up @@ -361,6 +381,58 @@ describe("REST API", function() {
expectedHttpStatus : httpStatus.UNAUTHORIZED,
expectedStatusText : 'error',
expectedResponseData : null
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return createAuthorizationHeader(user1.accessToken);
},
dataToUpload : invalidChannelName1.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName1.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return createAuthorizationHeader(user1.accessToken);
},
dataToUpload : invalidChannelName2.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName2.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return createAuthorizationHeader(user1.accessToken);
},
dataToUpload : invalidChannelName3.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName3.response,
},
{
description : "Should fail to upload to a feed if one or more channel names is invalid",
url : function() {
return ESDR_FEEDS_API_URL + "/" + feed1.id;
},
headers : function() {
return createAuthorizationHeader(user1.accessToken);
},
dataToUpload : invalidChannelName4.request,
expectedHttpStatus : httpStatus.UNPROCESSABLE_ENTITY,
expectedStatusText : 'error',
expectedResponseData : invalidChannelName4.response,
}
].forEach(executeUploadTest);

Expand All @@ -369,4 +441,4 @@ describe("REST API", function() {
}); // End To /feeds method
}); // End Upload
}); // End Feeds
}); // End REST API
}); // End REST API
6 changes: 6 additions & 0 deletions test/fixtures/feed-upload-invalid-channel-name-1-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"channel_names" : ["my channel"],
"data" : [
[1441856362, 42]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "data" : ["my channel"] }
6 changes: 6 additions & 0 deletions test/fixtures/feed-upload-invalid-channel-name-2-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"channel_names" : ["this_IS_valid", "this+is+not", "also_valid", "neither[is]this"],
"data" : [
[1441856362, 42, 43, 44, 45]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "data" : ["this+is+not", "neither[is]this"] }
15 changes: 15 additions & 0 deletions test/fixtures/feed-upload-invalid-channel-name-3-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"channel_names" : [
"i-am-valid",
" i am not!",
"hey.mom.look.i.am.valid",
"but..i..am..not",
".another-invalid",
"and-one-more."
],
"data" : [
[1441856362, 1, 2, 3, 4, 5, 6]
]
}
]
Loading

0 comments on commit 630eb35

Please sign in to comment.