Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #92

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ app.listen(app.get('port'), function () {
app.get('port') +
'. Ctrl + C for exit.');
});

module.exports = app;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"body-parser": "~1.17.1",
"browser-sync": "^2.18.8",
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"cloudinary": "^1.8.0",
"connect-livereload": "^0.6.0",
"cookie-parser": "~1.4.3",
Expand Down
154 changes: 154 additions & 0 deletions src/tests/authCtrls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* eslint no-unused-vars: 'off' */
// const assert = require('assert');
let chai = require('chai');
let chaiHttp = require('chai-http');
let should = chai.should();
let server = require('../../app');
chai.use(chaiHttp);

const dataWithBadRepeat = {
password: 'pass',
name: 'Super Name',
email: '[email protected]',
passwordRepeat: 'password'
};
const dataBadSpaces = {
password: ' ',
name: ' ',
email: ' ',
passwordRepeat: ' '
};
const repeatData = {
password: '1',
name: 'Name',
email: '[email protected]',
passwordRepeat: '1'
};
const dataWithInvalidEmail = {
password: '1',
name: 'Name',
email: 'bugiMail',
passwordRepeat: '1'
};

describe('Sign Up', () => {
it('Разные пароли', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signup')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(dataWithBadRepeat)
.end((err, res) => {
res.should.have.status(409);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Пароли не совпадают');
done();
});
});

it('Строки состящие из пробелов', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signup')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(dataBadSpaces)
.end((err, res) => {
res.should.have.status(409);
res.body.should.be.a('object');
res.body.should.have.property('message').not.eql('Пользователь с таким email уже зарегестрирован');
done();
});
});

it('Почта, которая уже существует', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signup')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(repeatData)
.end((err, res) => {
res.should.have.status(409);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Пользователь с таким email уже зарегестрирован');
done();
});
});

it('Невалидная почта', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signup')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(dataWithInvalidEmail)
.end((err, res) => {
res.should.have.status(409);
res.body.should.be.a('object');
res.body.should.have.property('message').not.eql('Пользователь с таким email уже зарегестрирован');
done();
});
});
});

const validData = {
password: '1',
email: 'bugiMail'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email не валидный

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

просто он в базе лежит, а я других паролей не помню)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

погоди, а ты прям к реальной базе подключаешься?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

честно... сам не понял. почему то только 2 прошли туда

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по сути нужно замокать БД, это как то через proxy делается
Просто я вот щас удалю того юзера и все повалится, так не должно быть.
В целом хорошо, но эт касяк)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут и паспорт надо заменять получается... дикость) будет сложна)))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ага :D

};
const invalidDataPass = {
password: '2',
email: 'bugiMail'
};
const invalidDataMail = {
password: '1',
email: '[email protected]'
};

describe('Sign In', () => {
it('Валидные данные', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signin')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(validData)
.end((err, res) => {
res.should.have.status(200);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('OK');
done();
});
});

it('Не валидный пароль', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signin')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(invalidDataPass)
.end((err, res) => {
res.should.have.status(403);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Неверный пароль');
done();
});
});

it('Не валидный email', function (done) {
this.timeout(4000);
chai.request(server)
.post('/signin')
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(invalidDataMail)
.end((err, res) => {
res.should.have.status(403);
res.body.should.be.a('object');
res.body.should.have.property('message').eql('Юзера с данным email не существует');
done();
});
});
});