Browse Source

add entries tests

pull/342/head
Guillaume Vincent 8 years ago
parent
commit
6f4d10d429
2 changed files with 58 additions and 0 deletions
  1. +16
    -0
      src/services/entries.js
  2. +42
    -0
      tests/services/entries.tests.js

+ 16
- 0
src/services/entries.js View File

@@ -0,0 +1,16 @@
import request from 'axios';

export default {
create(entry) {
return request.post('/api/entries/', entry)
.then((response) => {
return response;
});
},
all(){
return request.get('/api/entries/')
.then((response) => {
return response;
});
}
};

+ 42
- 0
tests/services/entries.tests.js View File

@@ -0,0 +1,42 @@
import assert from 'assert';
import entries from '../../src/services/entries';
import nock from 'nock';

suite('Entries', () => {
var entry = {
"site": "twitter.com",
"password": {
"counter": 1,
"settings": [
"lowercase",
"uppercase",
"numbers",
"symbols"
],
"length": 12
},
"email": "guillaume@oslab.fr",
};

test('should make a post request to create an entry', (done) => {
nock('http://localhost/')
.post('/api/entries/', entry)
.reply(201, {}, {'Content-Type': 'application/json'});
entries.create(entry)
.then((response) => {
assert.equal(201, response.status);
done();
});
});
test('should get all entries', (done) => {
nock('http://localhost/')
.get('/api/entries/')
.reply(200, {entries: []}, {'Content-Type': 'application/json'});
entries.all()
.then((response) => {
assert.equal(200, response.status);
assert.equal(0, response.data.entries.length);
done();
});
});
});

Loading…
Cancel
Save