FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added a client/server test. by eddyystop · Pull Request #99 · feathersjs/feathers-chat · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (4) .json  (2) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
60 changes: 60 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
100644 → 100755
This file contains hidden or 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
Expand Up @@ -23,11 +23,11 @@
},
"scripts": {
"test": "npm run eslint && npm run coverage",
"coverage": "npm run clean && NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha -- test/ --recursive --exit",
"coverage": "npm run clean && NODE_ENV=test istanbul cover node_modules/mocha/bin/_mocha -- test/ --timeout 5000 --recursive --exit",
"eslint": "eslint src/. test/. --config .eslintrc.json --fix",
"start": "node src/",
"clean": "shx rm -rf test/data/",
"mocha": "npm run clean && NODE_ENV=test mocha test/ --recursive --exit"
"mocha": "npm run clean && NODE_ENV=test mocha test/ --timeout 5000 --recursive --exit"
},
"dependencies": {
"@feathersjs/authentication": "^2.1.7",
Expand All @@ -47,12 +47,14 @@
"winston": "^3.0.0"
},
"devDependencies": {
"@feathersjs/client": "^3.5.6",
"eslint": "^5.3.0",
"feathers-memory": "^2.1.3",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^5.2.0",
"request": "^2.87.0",
"request-promise": "^4.2.2",
"shx": "^0.3.2"
"shx": "^0.3.2",
"socket.io-client": "^2.1.1"
}
}
100 changes: 100 additions & 0 deletions test/a-client-users.test.js
This file contains hidden or 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,100 @@
const assert = require('assert');
const feathersClient = require('@feathersjs/client');
const io = require('socket.io-client');
const app = require('../src/app');

const host = app.get('host');
const port = app.get('port');
const email = 'login@example.com';
const password = 'login';

describe('\'users\' service - client', function () {
this.timeout(10000);
let server;
let client;

before(async () => {
await app.service('users').create({ email, password });

server = app.listen(port);
server.on('listening', async () => {
// eslint-disable-next-line no-console
console.log('Feathers application started on http://%s:%d', host, port);
});

client = await makeClient(host, port, email, password);
});

after(() => {
client.logout();
server.close();
});

describe('Run tests using client and server', () => {
it('registered the service', () => {
const service = client.service('users');

assert.ok(service, 'Registered the service');
});

it('creates a user, encrypts password and adds gravatar', async () => {
const user = await client.service('users').create({
email: 'testclient@example.com',
password: 'secret'
});

// Verify Gravatar has been set to what we'd expect
assert.equal(user.avatar, 'https://s.gravatar.com/avatar/1b9c869fa7a93e59463c31a377fe0cf6?s=60');
// Makes sure the password got encrypted
assert.ok(user.password !== 'secret');
});

it('removes password for external requests', async () => {
// Setting `provider` indicates an external request
const params = { provider: 'rest' };

const user = await client.service('users').create({
email: 'testclient2@example.com',
password: 'secret'
}, params);

// Make sure password has been remove
assert.ok(!user.password);
});
});
});

async function makeClient(host, port, email, password) {
const client = feathersClient();
const socket = io(`http://${host}:${port}`, {
transports: ['websocket'], forceNew: true, reconnection: false, extraHeaders: {}
});
client.configure(feathersClient.socketio(socket));
client.configure(feathersClient.authentication({
storage: localStorage()
}));

await client.authenticate({
strategy: 'local',
email,
password,
});

return client;
}

function localStorage () {
const store = {};

return {
setItem (key, value) {
store[key] = value;
},
getItem (key) {
return store[key];
},
removeItem (key) {
delete store[key];
}
};
}
Empty file modified test/app.test.js
100644 → 100755
Empty file.
Empty file modified test/services/messages.test.js
100644 → 100755
Empty file.
Empty file modified test/services/users.test.js
100644 → 100755
Empty file.

Back | FazBrowse Home | New Git URL