This repository has been archived by the owner on Sep 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
env: | ||
es6: true | ||
node: true | ||
mocha: true | ||
extends: 'eslint:recommended' | ||
parserOptions: | ||
sourceType: module | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
const request = require('request'); | ||
var exports = module.exports = {}; | ||
|
||
const baseUrl = process.env.MAILDROP_URL || 'http://maildrop.cc'; | ||
|
||
exports.suggestion = () => { | ||
return new Promise((resolve, reject) => { | ||
let options = { | ||
method: 'GET', | ||
url: baseUrl + '/api/suggestion', | ||
json: true, | ||
headers: { 'cache-control': 'no-cache' } | ||
}; | ||
|
||
request(options, (error, response, body) => { | ||
if(error) return reject(error); | ||
return resolve(body.suggestion); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.blocked = () => { | ||
return new Promise((resolve, reject) => { | ||
let options = { | ||
method: 'GET', | ||
url: baseUrl + '/api/blocked', | ||
json: true, | ||
headers: { 'cache-control': 'no-cache' } | ||
}; | ||
|
||
request(options, (error, response, body) => { | ||
if(error) return reject(error); | ||
return resolve(body.blocked); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.getInbox = (mailBox) => { | ||
return new Promise((resolve, reject) => { | ||
if(!mailBox) return reject(new Error('mailBox required.')); | ||
|
||
let options = { | ||
method: 'GET', | ||
url: baseUrl + '/api/inbox/' + mailBox, | ||
json: true, | ||
headers: { 'cache-control': 'no-cache' } | ||
}; | ||
|
||
request(options, (error, response, body) => { | ||
if(error) return reject(error); | ||
return resolve(body); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.getEmail = (mailBox, emailId) => { | ||
return new Promise((resolve, reject) => { | ||
if(!(mailBox && emailId)) return reject(new Error('mailBox required.')); | ||
|
||
let options = { | ||
method: 'GET', | ||
url: baseUrl + '/api/inbox/' + mailBox + '/' + emailId, | ||
json: true, | ||
headers: { 'cache-control': 'no-cache' } | ||
}; | ||
|
||
request(options, (error, response, body) => { | ||
if(error) return reject(error); | ||
return resolve(body); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.deleteEmail = (mailBox, emailId) => { | ||
return new Promise((resolve, reject) => { | ||
if(!(mailBox && emailId)) return reject( | ||
new Error('mailBox and emailId required.') | ||
); | ||
|
||
let options = { | ||
method: 'DELETE', | ||
url: baseUrl + '/api/inbox/' + mailBox + '/' + emailId, | ||
json: true, | ||
headers: { 'cache-control': 'no-cache' }, | ||
followRedirect: true | ||
}; | ||
|
||
request(options, (error, response, body) => { | ||
if(error) return reject(error); | ||
return resolve(body); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
const path = require('path'); | ||
|
||
const maildrop = require(path.join(__dirname, '..', 'src', 'maildrop')); | ||
|
||
chai.use(chaiAsPromised); | ||
chai.should(); | ||
|
||
const mailBox = 'f'; | ||
|
||
describe('suggestion()', function() { | ||
it('should return without error', function() { | ||
return maildrop.suggestion().should.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
describe('blocked()', function() { | ||
it('should return without error', function() { | ||
return maildrop.blocked().should.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
describe('getInbox(mailBox)', function() { | ||
it('should be fulfilled without error', function() { | ||
return maildrop.getInbox(mailBox).should.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
describe('getInbox()', function() { | ||
it('should be rejected with error', function() { | ||
return maildrop.getInbox().should.eventually.be.rejected; | ||
}); | ||
}); | ||
|
||
describe('getEmail(mailBox, mailBox)', function() { | ||
it('should be fulfilled without error', function() { | ||
return maildrop.getEmail(mailBox, mailBox).should.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
describe('getEmail()', function() { | ||
it('should be rejected with error', function() { | ||
return maildrop.getEmail().should.eventually.be.rejected; | ||
}); | ||
}); | ||
|
||
describe('deleteEmail(mailBox, mailBox)', function() { | ||
it('should be fulfilled without error', function() { | ||
return maildrop.deleteEmail(mailBox, mailBox).should.eventually.be.fulfilled; | ||
}); | ||
}); | ||
|
||
describe('deleteEmail()', function() { | ||
it('should be rejected with error', function() { | ||
return maildrop.deleteEmail().should.eventually.be.rejected; | ||
}); | ||
}); |