Skip to content

Commit

Permalink
Melhora organização dos testes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpirola committed Dec 16, 2015
1 parent 09eae0c commit 5c8185a
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 228 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
"name": "processador-inscricao-evento",
"version": "0.0.2",
"description": "Processador de inscrições em eventos que utiliza uma planilha no Google Drive para controlar o envio de e-mail para pagamento e para confirmação da inscrição",
"main": "bin/www",
"main": "src/server.js",
"scripts": {
"start": "./node_modules/.bin/babel-node ./src/server.js",
"postinstall": "./node_modules/.bin/babel ./src/ -d ./dist/",
"test": "./node_modules/.bin/jasmine",
"generate-docs": "./node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
},
Expand Down
6 changes: 6 additions & 0 deletions spec/app_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('App is configured and working', function () {
it('Given enviroment is set to production')
it('When try to start listen on port 3000')
it('Then stylesheet must be generated')
it('And javascript must be generated')
})
34 changes: 0 additions & 34 deletions spec/checkIfConfigIsOk/datasourceConfigIsEmptySpec.js

This file was deleted.

34 changes: 0 additions & 34 deletions spec/checkIfConfigIsOk/datasourceContentIsEmptySpec.js

This file was deleted.

37 changes: 0 additions & 37 deletions spec/checkIfConfigIsOk/datasourceIsNotAcessibleSpec.js

This file was deleted.

19 changes: 0 additions & 19 deletions spec/checkIfConfigIsOk/smtpServerIsNotConfiguredSpec.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import Check from '../../src/modules/check'
import Util from '../util'
import Util from '../support/util'

describe('SMTP server is not configured', () => {
beforeAll(function () {
process.env['GOOGLE_SPREADSHEET_KEY'] = 'xxxxx'
this.chk = new Check()
})
it('Given SMTP server details is not filled', () => {
expect(process.env['MAIL_SERVICE']).toBeUndefined();
expect(process.env['MAIL_USER']).toBeUndefined();
expect(process.env['MAIL_PASS']).toBeUndefined();
});
it('When Developer try to check if config is ok', () => {});
it('Then a message must be output with information required', function(done) {
this.chk.isValid(function(err, results) {
expect(err).toEqual('As configurações do envio do email não foram informados');
done()
})
});
});

describe('Command check done successfully', () => {
beforeAll(function () {
Expand Down
103 changes: 103 additions & 0 deletions spec/modules/datasource_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import Check from '../../src/modules/check'

describe('Datasource config is empty', () => {
beforeAll(function () {
process.env['MAIL_SERVICE'] = 'gmail'
process.env['MAIL_USER'] = '[email protected]'
process.env['MAIL_PASS'] = '123'
delete(process.env['GOOGLE_CREDS'])
this.chk = new Check()
})
it('Given E-mail is configured and could be send', () => {
expect(process.env['MAIL_SERVICE']).toBeDefined()
expect(process.env['MAIL_USER']).toBeDefined()
expect(process.env['MAIL_PASS']).toBeDefined()
})
it('And Datasource config is empty', () => {
expect(process.env['GOOGLE_SPREADSHEET_KEY']).toBeUndefined()
expect(process.env['GOOGLE_CREDS']).toBeUndefined()
})
it('When Developer try to check if config is ok', () => {})

it('Then output a message with information required', function (done) {
this.chk.isValid(function (err, results) {
expect(err).toBe('As configurações da fonte de dados não foram informados')
done()
})
})

afterAll( () => {
delete process.env['MAIL_SERVICE']
delete process.env['MAIL_USER']
delete process.env['MAIL_PASS']
})
})

describe('Datasource content is empty', () => {
beforeAll(function () {
process.env['MAIL_SERVICE'] = 'gmail'
process.env['MAIL_USER'] = '[email protected]'
process.env['MAIL_PASS'] = '123'

process.env['GOOGLE_SPREADSHEET_KEY'] = '1sEMeSOtywIqCsBCaHCJlNWYOsujGm_1gxX_FVQ8iBvQ'
this.chk = new Check()
})
it('Given E-mail is configured and could be send', () => {
expect(process.env['MAIL_SERVICE']).toBeDefined()
expect(process.env['MAIL_USER']).toBeDefined()
expect(process.env['MAIL_PASS']).toBeDefined()
})
it('And Datasource config is valid', () => {
expect(process.env['GOOGLE_SPREADSHEET_KEY']).toBeDefined()
})
it('When Developer try to process all subscriptions', () => {})
it('Then a message must be output with error details', function (done) {
this.chk.isValid(function (err, results) {
expect(err).toBe('Datasource não pode ser vazio.')
done()
})
});
afterAll( () => {
delete process.env['MAIL_SERVICE']
delete process.env['MAIL_USER']
delete process.env['MAIL_PASS']

delete process.env['GOOGLE_SPREADSHEET_KEY']
})
})

describe('Datasource is not acessible', () => {
beforeAll(function () {
process.env['MAIL_SERVICE'] = 'gmail'
process.env['MAIL_USER'] = '[email protected]'
process.env['MAIL_PASS'] = '123'

process.env['GOOGLE_SPREADSHEET_KEY'] = 'xxxxxxx'
process.env['GOOGLE_CREDS'] = '{"client_email":"[email protected]","private_key":"ddd"}'
this.chk = new Check()
})
it('Given E-mail is configured and could be send', () => {
expect(process.env['MAIL_SERVICE']).toBeDefined()
expect(process.env['MAIL_USER']).toBeDefined()
expect(process.env['MAIL_PASS']).toBeDefined()
})
it('And Datasource config is valid', () => {
expect(process.env['GOOGLE_SPREADSHEET_KEY']).toBeDefined()
expect(process.env['GOOGLE_CREDS']).toBeDefined()
})
it('When Developer try to check if configs are ok', () => {})
it('Then output a message with information required', function (done) {
this.chk.isValid(function (err, results) {
expect(err).toEqual('As configurações fornecidas para fonte de dados não são válidosError: HTTP error 400: Bad Request "A planilha deste URL não foi encontrada. Verifique se você tem o URL correto e se o proprietário da planilha não a excluiu."');
done()
})
})
afterAll( () => {
delete process.env['MAIL_SERVICE']
delete process.env['MAIL_USER']
delete process.env['MAIL_PASS']

delete process.env['GOOGLE_SPREADSHEET_KEY']
delete process.env['GOOGLE_CREDS']
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Check from '../../src/modules/check'
import Util from '../util'
import Util from '../support/util'

describe('E-mail could not be send with SMTP server', () => {
beforeAll(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import onRegister from '../../src/modules/rules/onRegister'
import Process from '../../src/modules/process'
import Mailer from '../../src/modules/mailer'
import Util from '../util'
import Util from '../support/util'

describe('Rules has invalid options', () => {
beforeAll(function () {
Expand Down Expand Up @@ -42,8 +42,9 @@ describe('Rules has invalid options', () => {
let that = this
that.prc.run(function (err, results) {
expect(err)
.toEqual(['-> Error: E-mail inválido encontrado: lucaspirolagmail.com'].join('\n'))
.toEqual(['-> E-mail inválido encontrado: lucaspirolagmail.com'].join('\n'))
done(err, results)
})
})
})

72 changes: 72 additions & 0 deletions spec/modules/rules/index_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Rules from '../../../src/modules/rules'
import Util from '../../support/util'
import Mailer from '../../../src/modules/mailer'
import onRegister from '../../../src/modules/rules/onRegister'

describe('Subscriber has invalid email (Rules)', () => {
beforeAll(function() {
let u = new Util()
let m = new Mailer()
m.setTransporter(u.mailerTransport())

this.rl = new Rules(u.validDatasource())
this.rl.setMailer(m)
spyOn(this.rl, 'warningOrganizer').and.callThrough()
spyOn(this.rl, 'invalidateSubscriber').and.callThrough()
this.rl.rows[0]["e-mail"] = 'inválidoemail/.com'
})
it('Given Datasource has at least 1 row', function () {
expect(this.rl.rows.length).toEqual(2)
})
it('And One Subscriber has invalid email', function() {
expect(this.rl.rows[0]["e-mail"]).toEqual('inválidoemail/.com')
})
it('When Organizer check if Subscriber fit rules', function (done) {
let that = this
that.rl.validate(function(err, results) {
expect(err).toBe(['E-mail inválido encontrado: inválidoemail/.com'].join('\n'))
expect(that.rl.valid).toBe(false)
done(err, results)
})
})
it('Then Organizer must receive a email warning about spreadsheet error', function () {
expect(this.rl.invalidateSubscriber).toHaveBeenCalled()
expect(this.rl.warningOrganizer).toHaveBeenCalled()
})
it('And Subscriber status should be set to "Inválida"', function () {
expect(this.rl.rows[0]["status"]).toEqual('Inválida')
})
})

describe('Subscriber already receive payment instructions (Rule 1)', () => {
beforeAll(function() {
let u = new Util()
let m = new Mailer()
let r = u.validDatasource()
r[0]['status'] = 'Boleto Enviado'
m.setTransporter(u.mailerTransport())

this.rl = new onRegister(r)
this.rl.setMailer(m)
spyOn(this.rl, 'warningOrganizer')
spyOn(this.rl, 'invalidateSubscriber')
spyOn(this.rl, 'sendInstructions').and.callThrough()
spyOn(this.rl, 'markSubscriberReceivedInstructions').and.callThrough()
})
it('Given Datasource has at least 1 row', function () {
expect(this.rl.rows.length).toEqual(2)
})
it('And Subscriber email is valid and status is "Boleto Enviado"', function () {
expect(this.rl.rows[0]["status"]).toEqual('Boleto Enviado')
})
it('When Subscribers not fit rules', function (done) {
let that = this
that.rl.validate(function(err, results) {
expect(that.rl.valid).toBe(true)
done(err, results)
})
})
it('Then Subscriber should not be changed', function () {
expect(this.rl.rows[0]["status"]).toEqual('Boleto Enviado')
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import onConfirmation from '../../src/modules/rules/onConfirmation'
import Mailer from '../../src/modules/mailer'
import Util from '../util'
import onConfirmation from '../../../src/modules/rules/onConfirmation'
import Mailer from '../../../src/modules/mailer'
import Util from '../../support/util'

describe('Subscriber made payment at bank (Rule 2)', function () {
beforeAll(function() {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Subscriber made payment at bank (Rule 2)', function () {

expect(this.rl.rows[0]["status"]).toEqual('Confirmado')
})
it('And Subscriber should receive an email with confirmation instructions', function () {
xit('And Subscriber should receive an email with confirmation instructions', function () {
expect(this.rl.markSubscriberMakePayment).toHaveBeenCalled()
expect(this.rl.sendConfirmationMesssage).toHaveBeenCalled()
})
Expand Down
Loading

0 comments on commit 5c8185a

Please sign in to comment.