mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-09-20 15:26:03 +08:00
added some API integration tests
This commit is contained in:
parent
9e767187cb
commit
a40dce26f1
21
Gruntfile.js
21
Gruntfile.js
|
@ -14,13 +14,32 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
src: ['test/**/*-test.js', 'imap-core/test/**/*-test.js']
|
src: ['test/**/*-test.js', 'imap-core/test/**/*-test.js']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
wait: {
|
||||||
|
server: {
|
||||||
|
options: {
|
||||||
|
delay: 7 * 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
shell: {
|
||||||
|
server: {
|
||||||
|
command: 'node server.js',
|
||||||
|
options: {
|
||||||
|
async: true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load the plugin(s)
|
// Load the plugin(s)
|
||||||
grunt.loadNpmTasks('grunt-eslint');
|
grunt.loadNpmTasks('grunt-eslint');
|
||||||
grunt.loadNpmTasks('grunt-mocha-test');
|
grunt.loadNpmTasks('grunt-mocha-test');
|
||||||
|
grunt.loadNpmTasks('grunt-shell-spawn');
|
||||||
|
grunt.loadNpmTasks('grunt-wait');
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
grunt.registerTask('default', ['eslint', 'mochaTest']);
|
grunt.registerTask('default', ['eslint', 'shell:server', 'wait:server', 'mochaTest', 'shell:server:kill']);
|
||||||
};
|
};
|
||||||
|
|
9
config/test.toml
Normal file
9
config/test.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[log]
|
||||||
|
level="error"
|
||||||
|
|
||||||
|
[dbs]
|
||||||
|
# mongodb connection string for the main database
|
||||||
|
mongo="mongodb://127.0.0.1:27017/wildduck-test"
|
||||||
|
|
||||||
|
# redis connection string
|
||||||
|
redis="redis://127.0.0.1:6379/13"
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "IMAP server built with Node.js and MongoDB",
|
"description": "IMAP server built with Node.js and MongoDB",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "grunt"
|
"test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Andris Reinman",
|
"author": "Andris Reinman",
|
||||||
|
@ -17,6 +17,9 @@
|
||||||
"grunt-cli": "^1.2.0",
|
"grunt-cli": "^1.2.0",
|
||||||
"grunt-eslint": "^20.0.0",
|
"grunt-eslint": "^20.0.0",
|
||||||
"grunt-mocha-test": "^0.13.2",
|
"grunt-mocha-test": "^0.13.2",
|
||||||
|
"grunt-shell-spawn": "^0.3.10",
|
||||||
|
"grunt-wait": "^0.1.0",
|
||||||
|
"icedfrisby": "^1.2.0",
|
||||||
"mocha": "^3.4.2"
|
"mocha": "^3.4.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -31,6 +34,7 @@
|
||||||
"libmime": "^3.1.0",
|
"libmime": "^3.1.0",
|
||||||
"libqp": "^1.1.0",
|
"libqp": "^1.1.0",
|
||||||
"mailsplit": "^4.0.2",
|
"mailsplit": "^4.0.2",
|
||||||
|
"mobileconfig": "^2.0.1",
|
||||||
"mongo-cursor-pagination": "^5.0.0",
|
"mongo-cursor-pagination": "^5.0.0",
|
||||||
"mongodb": "^2.2.30",
|
"mongodb": "^2.2.30",
|
||||||
"node-redis-scripty": "0.0.5",
|
"node-redis-scripty": "0.0.5",
|
||||||
|
|
191
test/api-test.js
Normal file
191
test/api-test.js
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
/*eslint no-unused-expressions: 0, prefer-arrow-callback: 0, no-console:0 */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const chai = require('chai');
|
||||||
|
const frisby = require('icedfrisby');
|
||||||
|
const Joi = require('joi');
|
||||||
|
|
||||||
|
const expect = chai.expect;
|
||||||
|
chai.config.includeStack = true;
|
||||||
|
|
||||||
|
const URL = 'http://localhost:8080';
|
||||||
|
|
||||||
|
let userId = false;
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('POST users')
|
||||||
|
.post(
|
||||||
|
URL + '/users',
|
||||||
|
{
|
||||||
|
username: 'testuser',
|
||||||
|
password: 'secretpass',
|
||||||
|
address: 'testuser@example.com',
|
||||||
|
name: 'test user'
|
||||||
|
},
|
||||||
|
{ json: true }
|
||||||
|
)
|
||||||
|
.expectStatus(200)
|
||||||
|
.expectJSONTypes({
|
||||||
|
success: Joi.boolean(),
|
||||||
|
id: Joi.string(),
|
||||||
|
error: Joi.string()
|
||||||
|
})
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
userId = response.id;
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id}')
|
||||||
|
.get(URL + '/users/' + userId)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.id).to.equal(userId);
|
||||||
|
expect(response.name).to.equal('test user');
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('PUT users/{id}')
|
||||||
|
.put(
|
||||||
|
URL + '/users/' + userId,
|
||||||
|
{
|
||||||
|
name: 'user test'
|
||||||
|
},
|
||||||
|
{ json: true }
|
||||||
|
)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id} – updated name')
|
||||||
|
.get(URL + '/users/' + userId)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.id).to.equal(userId);
|
||||||
|
expect(response.name).to.equal('user test');
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id}/addresses')
|
||||||
|
.get(URL + '/users/' + userId + '/addresses')
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.results.length).to.equal(1);
|
||||||
|
expect(response.results[0].address).to.equal('testuser@example.com');
|
||||||
|
expect(response.results[0].main).to.be.true;
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('POST users/{id}/addresses')
|
||||||
|
.post(
|
||||||
|
URL + '/users/' + userId + '/addresses',
|
||||||
|
{
|
||||||
|
address: 'alias1@example.com',
|
||||||
|
main: true
|
||||||
|
},
|
||||||
|
{ json: true }
|
||||||
|
)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('POST users/{id}/addresses')
|
||||||
|
.post(
|
||||||
|
URL + '/users/' + userId + '/addresses',
|
||||||
|
{
|
||||||
|
address: 'alias2@example.com'
|
||||||
|
},
|
||||||
|
{ json: true }
|
||||||
|
)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id}/addresses – updated listing')
|
||||||
|
.get(URL + '/users/' + userId + '/addresses')
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.results.length).to.equal(3);
|
||||||
|
response.results.sort((a, b) => a.id.localeCompare(b.id));
|
||||||
|
|
||||||
|
expect(response.results[0].address).to.equal('testuser@example.com');
|
||||||
|
expect(response.results[0].main).to.be.false;
|
||||||
|
|
||||||
|
expect(response.results[1].address).to.equal('alias1@example.com');
|
||||||
|
expect(response.results[1].main).to.be.true;
|
||||||
|
|
||||||
|
expect(response.results[2].address).to.equal('alias2@example.com');
|
||||||
|
expect(response.results[2].main).to.be.false;
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('DELETE users/{id}/addresses/{address}')
|
||||||
|
.delete(URL + '/users/' + userId + '/addresses/' + response.results[2].id)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id}/addresses – after DELETE')
|
||||||
|
.get(URL + '/users/' + userId + '/addresses')
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.results.length).to.equal(2);
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id} – updated address')
|
||||||
|
.get(URL + '/users/' + userId)
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.id).to.equal(userId);
|
||||||
|
expect(response.address).to.equal('alias1@example.com');
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
|
||||||
|
frisby
|
||||||
|
.create('GET users/{id}/mailboxes')
|
||||||
|
.get(URL + '/users/' + userId + '/mailboxes')
|
||||||
|
.expectStatus(200)
|
||||||
|
.afterJSON(response => {
|
||||||
|
expect(response).to.exist;
|
||||||
|
expect(response.success).to.be.true;
|
||||||
|
expect(response.results.length).to.be.gte(4);
|
||||||
|
expect(response.results[0].path).to.equal('INBOX');
|
||||||
|
})
|
||||||
|
.toss();
|
||||||
|
})
|
||||||
|
.toss();
|
Loading…
Reference in a new issue