Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5ce8ced
Rewrite throws to rejects on bad responses
arkadiusz-wieczorek Nov 3, 2016
79f1e55
Fix all then and catch chains
arkadiusz-wieczorek Nov 3, 2016
22d216d
Rewrite all test
arkadiusz-wieczorek Nov 3, 2016
8ab4435
Rewrite then catch chains in get/3.js
arkadiusz-wieczorek Nov 4, 2016
2d689a6
Add new test - Get all elements in accordance with query param
arkadiusz-wieczorek Nov 4, 2016
3848432
Add new test - Post new element without some fields (check non-existe…
arkadiusz-wieczorek Nov 4, 2016
9509e19
Add new collection
arkadiusz-wieczorek Nov 4, 2016
7d54723
Update .gitignore
arkadiusz-wieczorek Nov 4, 2016
0b99e13
Fix typo in .gitignore
arkadiusz-wieczorek Nov 4, 2016
d9c6ede
Add new test - Post new element without fields to collection without …
arkadiusz-wieczorek Nov 5, 2016
524dcdf
Add description for two test which sending empty objects
arkadiusz-wieczorek Nov 5, 2016
d10c544
Add new test - Post new element with fields which aren't declared in …
arkadiusz-wieczorek Nov 7, 2016
c4b875f
Add new test - Delete posted element from collection
arkadiusz-wieczorek Nov 7, 2016
d7d1d81
Add new test - Delete non-existing element from collection
arkadiusz-wieczorek Nov 7, 2016
41a3c4f
Add red color text to error in console
arkadiusz-wieczorek Nov 7, 2016
187d897
Add new test - Get with formData from collection
arkadiusz-wieczorek Nov 7, 2016
eee7054
Add new test - Login with incorrect credentials
arkadiusz-wieczorek Nov 7, 2016
0278660
Fix if statement for checking res.body
arkadiusz-wieczorek Nov 7, 2016
02084fa
Cleanup get/1.js
arkadiusz-wieczorek Nov 8, 2016
faf55b0
Add new test for PUT method - Update element of collection
arkadiusz-wieczorek Nov 8, 2016
05296d9
Add new test - Update element of collection by PUT method with incorr…
arkadiusz-wieczorek Nov 10, 2016
f39e07b
Add then chain in put/2.js
arkadiusz-wieczorek Nov 10, 2016
e70a88e
Add new test - Update element of collection by PUT method without req…
arkadiusz-wieczorek Nov 10, 2016
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ uploaded_files
*~
~*
\#*
_scenarios
28 changes: 17 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
"use strict";
const Promise = require("bluebird");
var scenarios = require('auto-load')('scenarios')
const pre = require("./pre-test.js");
var scenarios = require('auto-load')('scenarios');

require("./pre-test.js")()
.then(() => {
// scenarios/[method]/[scenario (key)]
// e.g. scenarios/post/1.js
pre()
.then(function(){
return Promise.each(
Object.keys(scenarios), (method) => {
for (var key in scenarios[method]) {
return scenarios[method][key]().then(() => console.log('→ scenario done'))
if(scenarios[method] instanceof Function){
return scenarios[method]();
}else{
return Promise.each(Object.keys(scenarios[method]), key => scenarios[method][key]());
}
}
)
})
.then(() => {
console.log("Tests run complete. Exiting with status 0.");
);
}).then(()=> {
console.log("\n\n\t✓ Success! Tests run complete. Exiting with status 0.\n\n");
process.exit(0);
})
.catch((err) => {
console.error(err);
console.log(err.stack);
console.log("\n\n\t✗ Tests failed. Exiting with status 1. See the above output for details.\n\n");
process.exit(1);
});
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
},
"homepage": "https://github.com/sealcode/sealious-integration-tests#readme",
"dependencies": {
"auto-load": "^2.1.0",
"bluebird": "^3.4.6",
"node-uuid": "^1.4.7",
"request": "^2.74.0",
"request-promise": "^4.1.1",
"sealious": "github:sealcode/sealious#alpha",
"sealious": "github:sealcode/sealious#default_config_delegation",
"sealious-datastore-mongo": "sealcode/sealious-datastore-mongo#alpha",
"sealious-www-server": "github:sealcode/sealious-www-server#alpha"
},
"devDependencies": {
"cli-color": "^1.1.0",
"request-debug": "^0.2.0"
}
}
30 changes: 25 additions & 5 deletions pre-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ module.exports = function(){
]
});

App.createCollection({
name: "without_required_values",
fields: [{ name: "number", type: "float" }]
});

App.createCollection({
name: "empty",
fields: [
{name: "number", type: "int"}
]
})
fields: [{ name: "number", type: "int" }]
});

return App.start();
App.createCollection({
name: "restricted",
fields: [],
access_strategy: {
default: "logged_in"
}
});

App.Logger.error = () => {}

return App.start()
.then(function(){
const datastore = App.ChipManager.get_datastore_chip();
return datastore.remove("users", {});
//.then(() => datastore.remove("sessions", {}));
}).then(function(){
return App;
});
};
47 changes: 47 additions & 0 deletions scenarios/delete/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// scenario #1
// TODO: Delete posted element from collection

"use strict";
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
var prepared_body = {
name: "Some title",
description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit."
}
return rp.post({
url: uri('collections/people'),
formData: prepared_body,
json: true,
resolveWithFullResponse: true
})
.then((res) => {
if (res.statusCode !== 201) {
throw new Error(clc.red('incorrect status code, received ' + res.statusCode))
} else {
var id = res.body.id
return rp.delete({
url: uri(`collections/people/${id}`),
json: true,
resolveWithFullResponse: true
})
}
})
.then((res) => {
if (res.body === undefined) {
if (res.statusCode !== 204) {
throw new Error(clc.red('incorrect status code, received ' + res.statusCode))
// http://stackoverflow.com/a/2342589
} else {
console.log("success!")
}
} else {
throw new Error(clc.red(`the response has body`))
}
})
};
26 changes: 26 additions & 0 deletions scenarios/delete/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// scenario #2
// TODO: Delete non-existing element from collection

"use strict";
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
var id = Math.random()
return rp.delete({
url: uri(`collections/people/${id}`),
json: true,
resolveWithFullResponse: true
})
.catch((res) => {
if (res.statusCode !== 404) {
throw new Error(clc.red('incorrect status code, received ' + res.statusCode))
} else {
console.log("success!")
}
})
};
25 changes: 13 additions & 12 deletions scenarios/get/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8080/api/v1/" + path;
var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
console.log('scenario #1')

return rp.get({
url: uri("collections/people/" + "_"),
json: true,
resolveWithFullResponse: true
}).then((res) => {
if (res.statusCode === 404) return res
else throw new Error('incorrect status code, received ' + res.statusCode)
}).then((res) => {
if (res.body.type === "not_found") return true
else throw new Error('incorrect type of response')
}).then(() => {
console.log("succcess!");
});
})
.then((res) => {
throw new Error(clc.red("Should have thrown a 404 error!"));
})
.catch((res) => {
if(res.statusCode !== 404 || res.error.message.type !== "not_found"){
throw new Error(clc.red("should have thrown a 404 not_found error"));
}
})

.then(() => console.log("succcess!"))
};
29 changes: 17 additions & 12 deletions scenarios/get/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8080/api/v1/" + path;
var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
console.log('scenario #2')

return rp.get({
url: uri("collections/peopl"), //`peopl` instead of `people`
json: true,
resolveWithFullResponse: true
}).then((res) => {
if (res.statusCode === 404) return res
else throw new Error('incorrect status code, received ' + res.statusCode)
}).then((res) => {
if (res.body.type === "bad_subject") return true
else throw new Error('incorrect type of response')
}).then(() => {
console.log("succcess!");
});
})
.then(() => {
throw new Error(clc.red("Should have thrown a 404 error!"));
})
.catch((res) => {
if (res.statusCode === 404){
if (res.error.message.type === "bad_subject"){
return true;
} else {
throw new Error(clc.red('incorrect status code, received ' + res.statusCode));
}
}
})

.then(() => console.log("succcess!"))
};
23 changes: 11 additions & 12 deletions scenarios/get/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8080/api/v1/" + path;
var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
console.log('scenario #3')

return rp.get({
url: uri("collections/empty"),
json: true,
resolveWithFullResponse: true
}).then((res) => {
if (res.statusCode === 200) return res
else throw new Error('incorrect status code, received ' + res.statusCode)
}).then((res) => {
if (res.body.length === 0) return true
else throw new Error('incorrect body')
}).then(() => {
console.log("succcess!");
});
})
.then((res) => {
if (res.statusCode !== 200){
throw new Error(clc.red('incorrect status code, received ' + res.statusCode))
} else {
if (res.body.length !== 0) throw new Error(clc.red('incorrect body'))
else console.log("success!")
}
})
};
45 changes: 45 additions & 0 deletions scenarios/get/4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// scenario #4
// TODO: Get all elements in accordance with query param

"use strict";
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
var prepared_body = {
name: "Some title",
description: "Lorem ipsum dolor sit amet, consectetur adipisicing elit."
}
return rp.post({
url: uri('collections/people'),
formData: prepared_body,
json: true,
resolveWithFullResponse: true
})
.then((res) => {
if (res.statusCode !== 201) {
throw new Error(clc.red('incorrect status code, received ' + res.statusCode))
} else {
return rp.get({
url: uri("collections/people?search=Lorem"),
json: true,
resolveWithFullResponse: true
})
}
})
.then((res) => {
if (res.body.length !== 0) {
if (res.body[0].description.original.search('Lorem') !== -1) {
console.log("success!")
} else {
throw new Error(clc.red(`the searched element don't fit to search keyword`))
}
} else {
throw new Error(clc.red(`the body in response on search keyword 'Lorem' doesn't have search results`))
}
})
};
26 changes: 26 additions & 0 deletions scenarios/get/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// scenario #5
// TODO: Get with formData from collection

"use strict";
var rp = require("request-promise");
var fs = require("fs");
var assert = require("assert");
var clc = require('cli-color');

var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function() {
return rp.get({
url: uri("collections/people"),
data: {name: "Some title2"},
json: true,
resolveWithFullResponse: true
})
.then((res) => {
throw new Error(clc.red("Should have thrown a error which is related to a useable body in GET request"))
})
.catch((res) => {
assert.equal(response.statusCode, 400);
console.log("succcess!")
});
};
29 changes: 29 additions & 0 deletions scenarios/login-with-incorrect-credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
var rp = require("request-promise");
//require('request-debug')(rp);
var fs = require("fs");
var assert = require("assert");

var uri = (path) => "http://localhost:8081/api/v1/" + path;

module.exports = function(){
const user = {username: "user", password: "password"};
const incorrect_user = {username: "u", password: "p"};

//register
return rp.post({
url: uri("users"),
formData: user
})
.then(() => {
return rp.post({
url: uri("sessions"),
formData: incorrect_user
})
})
.catch((res) => {
assert.equal(res.statusCode, 401);
console.log("success!")
})

};
Loading