Created
August 21, 2016 03:39
-
-
Save TimFletcher/51806e2000819d40523e9dcfb0d52108 to your computer and use it in GitHub Desktop.
This file contains 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
// Chimp globals | |
/* globals browser assert server client */ | |
// Meteor globals | |
/* globals Meteor, Package, Accounts */ | |
export default { | |
getUrl(path) { | |
const baseUrl = 'http://localhost:3100/'; | |
return `${baseUrl}${path}`; | |
}, | |
users: { | |
create() { | |
server.execute(() => { | |
const email = '[email protected]'; | |
const password = 'jkjkjkjk'; | |
let userId; | |
try { | |
const user = Meteor.users.findOne({ emails: { $elemMatch: { address: email } } }); | |
userId = user._id; | |
} catch (e) { | |
userId = Accounts.createUser({ | |
email, | |
password, | |
profile: { firstName: 'Tim', lastName: 'Fletcher' }, | |
}); | |
} | |
// Always reset user password as a test may have changed it | |
Accounts.setPassword(userId, password, { logout: false }); | |
}); | |
}, | |
// The server connection is for being able to do server calls from the test context that would | |
// be logged in as the user also. This is useful for doing setup calls typically. You're right | |
// in that it's not needed for what @timfletcher is doing in that instance. | |
serverLogin(user) { | |
server.call('login', { user: { email: user.email }, password: user.password }); | |
}, | |
clientLogin(credentials) { | |
// Need to work out set this globally, before all tests | |
browser.timeoutsAsyncScript(5000); | |
browser.url('http://localhost:3100'); // the client must be on a Meteor app page before you can call `execute` on it | |
browser.executeAsync((creds, done) => { | |
Meteor.loginWithPassword(creds.email, creds.password, done); | |
}, credentials); | |
}, | |
login(user) { | |
this.serverLogin(user); | |
this.clientLogin(user); | |
}, | |
logout() { | |
// Need to work out set this globally, before all tests | |
browser.timeoutsAsyncScript(5000); | |
server.call('logout'); | |
browser.executeAsync(done => Meteor.logout(done)); | |
}, | |
}, | |
common: { | |
reset() { | |
// Make sure the DDP connection is not logged in before clearing the database | |
server.call('logout'); | |
server.execute(() => { Package['xolvio:cleaner'].resetDatabase(); }); | |
}, | |
}, | |
}; |
This file contains 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
/* eslint-env mocha */ | |
/* eslint-disable func-names */ | |
// Chimp globals | |
/* globals browser assert server */ | |
import fixtures from './fixtures'; | |
describe('Change Password Form', () => { | |
beforeEach(() => { | |
fixtures.common.reset(); | |
fixtures.users.create(); | |
fixtures.users.login({ email: '[email protected]', password: 'jkjkjkjk' }); | |
browser | |
.url(fixtures.getUrl('settings')) | |
.click('#react-tabs-2'); | |
}); | |
afterEach(() => { | |
fixtures.users.logout(); | |
}); | |
it('can change password', () => { | |
browser | |
.setValue('input[name*="new-password"]', 'jkjkjkjk') | |
.click('.btn-primary') | |
.waitForVisible('.flash-message'); | |
assert.equal('Your password was updated successfully', browser.getText('.flash-message')); | |
}); | |
it('shows an error with a blank password', () => { | |
browser.click('.btn-primary'); | |
assert.equal('Password is required', browser.getText('.form-input-error')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment