mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #19411 from overleaf/ii-split-tests-helpers
[web] Move split test helper methods to a separate file GitOrigin-RevId: 9bcb429f2debf8f7ff4b071e32c9cf0038459b97
This commit is contained in:
parent
710cacad2d
commit
c005e99a3e
1 changed files with 60 additions and 0 deletions
60
services/web/test/acceptance/src/helpers/SplitTestHelper.js
Normal file
60
services/web/test/acceptance/src/helpers/SplitTestHelper.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
const { assert } = require('chai')
|
||||||
|
const { CacheFlow } = require('cache-flow')
|
||||||
|
|
||||||
|
const sendStaffRequest = async function (
|
||||||
|
staffUser,
|
||||||
|
{ method, path, payload, clearCache = true }
|
||||||
|
) {
|
||||||
|
const response = await staffUser.doRequest(method, {
|
||||||
|
uri: path,
|
||||||
|
json: payload,
|
||||||
|
})
|
||||||
|
if (clearCache) {
|
||||||
|
await CacheFlow.reset('split-test')
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
const createTest = async function (staffUser, payload) {
|
||||||
|
const response = await sendStaffRequest(staffUser, {
|
||||||
|
method: 'POST',
|
||||||
|
path: '/admin/api/split-test/create',
|
||||||
|
payload,
|
||||||
|
})
|
||||||
|
return response.body
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateTestConfig = async function (staffUser, payload) {
|
||||||
|
const response = await sendStaffRequest(staffUser, {
|
||||||
|
method: 'POST',
|
||||||
|
path: '/admin/api/split-test/update-config',
|
||||||
|
payload,
|
||||||
|
})
|
||||||
|
return response.body
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectResponse = async function (
|
||||||
|
staffUser,
|
||||||
|
{ method, path, payload },
|
||||||
|
{ status, body, excluding, excludingEvery }
|
||||||
|
) {
|
||||||
|
const result = await sendStaffRequest(staffUser, { method, path, payload })
|
||||||
|
|
||||||
|
assert.equal(result.response.statusCode, status)
|
||||||
|
if (body) {
|
||||||
|
if (excludingEvery) {
|
||||||
|
assert.deepEqualExcludingEvery(result.body, body, excludingEvery)
|
||||||
|
} else if (excluding) {
|
||||||
|
assert.deepEqualExcludingEvery(result.body, body, excluding)
|
||||||
|
} else {
|
||||||
|
assert.deepEqual(result.body, body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
sendStaffRequest,
|
||||||
|
createTest,
|
||||||
|
updateTestConfig,
|
||||||
|
expectResponse,
|
||||||
|
}
|
Loading…
Reference in a new issue