mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 03:37:20 +00:00
Merge pull request #2693 from overleaf/ta-acceptance-user-helper
Improve UserHelper in Acceptance Tests GitOrigin-RevId: 3dffc789a07197d6cc14715dee89da0feb40b506
This commit is contained in:
parent
35ef98781f
commit
be7a1abb13
1 changed files with 48 additions and 0 deletions
|
@ -1,7 +1,9 @@
|
|||
const { expect } = require('chai')
|
||||
const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager')
|
||||
const Settings = require('settings-sharelatex')
|
||||
const UserCreator = require('../../../../app/src/Features/User/UserCreator')
|
||||
const UserGetter = require('../../../../app/src/Features/User/UserGetter')
|
||||
const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
|
||||
const request = require('request-promise-native')
|
||||
|
||||
let globalUserNum = 1
|
||||
|
@ -83,6 +85,25 @@ class UserHelper {
|
|||
this.request = this.request.defaults(defaults)
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a request for the user and run expectations on the response.
|
||||
* @param {object} [requestOptions] options to pass to request
|
||||
* @param {object} [responseExpectations] expectations:
|
||||
* - {Int} statusCode the expected status code
|
||||
* - {RegEx} message a matcher for the message
|
||||
*/
|
||||
async expectErrorOnRequest(requestOptions, responseExpectations) {
|
||||
let error
|
||||
try {
|
||||
await this.request(requestOptions)
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
expect(error).to.exist
|
||||
expect(error.statusCode).to.equal(responseExpectations.statusCode)
|
||||
expect(error.message).to.match(responseExpectations.message)
|
||||
}
|
||||
|
||||
/* async http api call methods */
|
||||
|
||||
/**
|
||||
|
@ -173,6 +194,22 @@ class UserHelper {
|
|||
return new UserHelper(user)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing user via UserUpdater and return the updated UserHelper
|
||||
* instance.
|
||||
* All args passed to UserUpdater.getUser.
|
||||
* @returns {UserHelper}
|
||||
*/
|
||||
static async updateUser(...args) {
|
||||
const user = await UserUpdater.promises.updateUser(...args)
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`no user found for args: ${JSON.stringify([...args])}`)
|
||||
}
|
||||
|
||||
return new UserHelper(user)
|
||||
}
|
||||
|
||||
/**
|
||||
* Login to existing account via request and return UserHelper instance
|
||||
* @param {object} userData
|
||||
|
@ -205,6 +242,17 @@ class UserHelper {
|
|||
return userHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is logged in by requesting an endpoint behind authentication.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
async isLoggedIn() {
|
||||
const response = await this.request.get('/user/sessions', {
|
||||
followRedirect: true
|
||||
})
|
||||
return response.request.path === '/user/sessions'
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new account via request and return UserHelper instance.
|
||||
* If userData is not provided the default email and password will be used.
|
||||
|
|
Loading…
Add table
Reference in a new issue