mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[web] add includeReferer flag to SplitTestHandler.getAssignment (#33235)
* [web] add includeReferer flag to SplitTestHandler.getAssignment * [web] tests: migrate User.getSplitTestAssignment to async/await I don't want to fight with callbacks and optional arguments. Just move it to async/await. New tests should use async/await, so there is no point in making this work in callback-hell. * [web] remove unused URL import GitOrigin-RevId: 6251001e6ba7354f704fa663be8ef365ca0b9d23
This commit is contained in:
@@ -53,10 +53,11 @@ before('start main app', function (done) {
|
||||
route => route.path && route.path === '/dev/csrf',
|
||||
router => {
|
||||
router.get('/dev/split_test/get_assignment', (req, res) => {
|
||||
const { splitTestName } = req.query
|
||||
const { splitTestName, includeReferer } = req.query
|
||||
SplitTestHandler.promises
|
||||
.getAssignment(req, res, splitTestName, {
|
||||
sync: true,
|
||||
includeReferer: includeReferer === 'true',
|
||||
})
|
||||
.then(assignment => res.json(assignment))
|
||||
.catch(error => {
|
||||
|
||||
@@ -100,37 +100,6 @@ class User {
|
||||
})
|
||||
}
|
||||
|
||||
getSplitTestAssignment(splitTestName, query, callback) {
|
||||
if (!callback) {
|
||||
callback = query
|
||||
}
|
||||
const params = new URLSearchParams({
|
||||
splitTestName,
|
||||
...query,
|
||||
}).toString()
|
||||
this.request.get(
|
||||
{
|
||||
url: `/dev/split_test/get_assignment?${params}`,
|
||||
},
|
||||
(err, response, body) => {
|
||||
if (err != null) {
|
||||
return callback(err)
|
||||
}
|
||||
if (response.statusCode !== 200) {
|
||||
return callback(
|
||||
new Error(
|
||||
`get split test assignment failed: status=${
|
||||
response.statusCode
|
||||
} body=${JSON.stringify(body)}`
|
||||
)
|
||||
)
|
||||
}
|
||||
const assignment = JSON.parse(response.body)
|
||||
callback(null, assignment)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
doSessionMaintenance(callback) {
|
||||
this.request.post(
|
||||
{
|
||||
@@ -1350,4 +1319,29 @@ User.promises.prototype.doRequest = async function (method, params) {
|
||||
})
|
||||
}
|
||||
|
||||
User.promises.prototype.getSplitTestAssignment = async function (
|
||||
splitTestName,
|
||||
query,
|
||||
referer,
|
||||
includeReferer
|
||||
) {
|
||||
const params = new URLSearchParams({
|
||||
splitTestName,
|
||||
includeReferer,
|
||||
...query,
|
||||
}).toString()
|
||||
const { response, body } = await this.doRequest('GET', {
|
||||
url: `/dev/split_test/get_assignment?${params}`,
|
||||
headers: { referer },
|
||||
})
|
||||
if (response.statusCode !== 200) {
|
||||
throw new Error(
|
||||
`get split test assignment failed: status=${
|
||||
response.statusCode
|
||||
} body=${JSON.stringify(body)}`
|
||||
)
|
||||
}
|
||||
return JSON.parse(response.body)
|
||||
}
|
||||
|
||||
export default User
|
||||
|
||||
Reference in New Issue
Block a user