Skip to content

Commit

Permalink
better handling order status and fixing user login test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanmtz committed Dec 19, 2023
1 parent b59643a commit 1fb145e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
14 changes: 7 additions & 7 deletions frontend/src/components/task/task-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ class TaskPayment extends Component {
/>
<Button
onClick={ this.payTask }
style={ { float: 'right', margin: 10 } }
style={ { float: 'right' } }
variant='contained'
color='primary'
disabled={ !this.props.assigned }
disabled={ !this.props.assigned || (order.status === 'open' && order.status !== 'succeeded' && !order.paid) }
>
<RedeemIcon style={ { marginRight: 10 } } />
<FormattedMessage id='task.payment.pay.button.credit' defaultMessage='Pay $ {value}' values={ {
Expand All @@ -368,7 +368,7 @@ class TaskPayment extends Component {
</div>
)) : (
<div>
<Alert severity='info'>
<Alert severity='info' gutterBottom>
<FormattedMessage id='task.payment.noTransfers' defaultMessage='No bounties for this issue' />
</Alert>
</div>
Expand All @@ -377,10 +377,10 @@ class TaskPayment extends Component {
</TabContainer>
</div>
<DialogContentText>
<span style={ { display: 'inline-block', margin: 20 } }>
<div>
{ !this.props.paid ? (
<div>
<Alert severity='warning'>
<Alert severity='warning' gutterBottom>
{ this.props.assigned
? this.props.intl.formatMessage(messages.transferMessage, {
to: sendTo(this.props.assigned).username || 'unknown',
Expand Down Expand Up @@ -444,7 +444,7 @@ class TaskPayment extends Component {
} } />
</div>
) }
</span>
</div>
</DialogContentText>
<Divider />
{ hasOrders() ? (
Expand All @@ -455,7 +455,7 @@ class TaskPayment extends Component {
style={ { float: 'right', margin: 10 } }
variant='contained'
color='primary'
disabled={ !this.props.assigned || this.props.transferId || this.state.currentTab === 2 }
disabled={ !this.props.assigned || this.props.transferId}
>
<RedeemIcon style={ { marginRight: 10 } } />
<FormattedMessage id='task.payment.start.payTo' defaultMessage='Pay $ {value}' values={ {
Expand Down
2 changes: 0 additions & 2 deletions models/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ module.exports = (sequelize, DataTypes) => {
oldValues: Object.values(instance.previous()),
newValues: changed.map(v => instance.dataValues[v])
})
// eslint-disable-next-line no-console
console.log('Task History create', taskHistory)
}
catch (e) {
// eslint-disable-next-line no-console
Expand Down
2 changes: 1 addition & 1 deletion test/contact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const api = require('../server')
const ContactMail = require('../modules/mail/contact')
const agent = request.agent(api)

xdescribe("Contact", () => {
describe("Contact", () => {
describe('Contact recruiters', () => {
xit('should contact recruiters', (done) => {
chai.use(spies);
Expand Down
35 changes: 20 additions & 15 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
const testEmail = 'teste@gmail.com' + Math.random()
const testPassword = 'teste' + Math.random()
const testName = 'Tester' + Math.random()
const testEmail = `teste+${Math.random()*100}@gmail.com`
const testPassword = 'test'
const testName = 'Test'

const register = (agent, params = {}) => {
params.email = params.email || testEmail
params.password = params.password || testPassword
params.confirmPassword = params.password || testPassword
params.name = params.name || testName
return agent
.post('/auth/register')
.send(params)
}

const login = (agent, params = {}) => {
params.email = params.email || testEmail
params.username = params.email || testEmail
params.password = params.password || testPassword
return agent
.post('/authorize/local')
.send(params)
.type('form')
}

const activate = (agent, res) => {
return agent
.get(`/auth/activate?token=${res.body.activation_token}&userId=${res.body.id}`)
}

const registerAndLogin = (agent, registerParams = {
email: testEmail,
password: testPassword
}, loginParams = {
email: testEmail,
password: testPassword
}) => {
return register(agent, registerParams)
const registerAndLogin = (agent) => {
return register(agent)
.then((a) => {
return activate(agent, a).then((active) => {
console.log('user activated', active.body)
return login(agent, loginParams).then(
return login(agent).then(
(res) => {
console.log('login response', res.text)
return res
}
).catch((e) => {
Expand All @@ -50,6 +44,17 @@ const registerAndLogin = (agent, registerParams = {
console.log('error on register', e)
})
}

const createTask = (agent, params = {}) => {
params.provider = params.provider || 'github'
params.url = params.url || 'https://github.com/worknenjoy/truppie/issues/120'
registerAndLogin(agent).then((res) => {
return agent
.post('/tasks')
.send(params)
})
}

module.exports = {
register,
login,
Expand Down
2 changes: 1 addition & 1 deletion test/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const agent = request.agent(api)
const SendMail = require('../modules/mail/mail')
const { scripts } = require('../scripts')

xdescribe('Scripts', () => {
describe('Scripts', () => {
beforeEach(() => {
models.Task.destroy({where: {}, truncate: true, cascade: true}).then(function(rowDeleted){ // rowDeleted will return number of rows deleted
if(rowDeleted === 1){
Expand Down
5 changes: 2 additions & 3 deletions test/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,14 @@ describe("Users", () => {
.type('form')
.expect('Content-Type', /json/)
.end((err, res) => {
console.log('res.body', res.body, err)
agent
.post('/authorize/local')
.send({email: '[email protected]', password: 'teste'})
.send({username: '[email protected]', password: 'teste'})
.type('form')
.expect(302)
.end((err, res) => {
console.log('res.headers.location', res.headers.location)
expect(res.statusCode).to.equal(302);
expect(res.text).to.include('token')
done(err);
})
}
Expand Down

0 comments on commit 1fb145e

Please sign in to comment.