mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[web] remove generic analytics service proxy (#36934)
GitOrigin-RevId: 19b3613b7cc84e73ad556067da1b3cd2f956e1c5
This commit is contained in:
@@ -2,6 +2,7 @@ import { expect } from 'chai'
|
||||
import UserHelper from './helpers/User.mjs'
|
||||
import request from './helpers/request.js'
|
||||
import Features from '../../../app/src/infrastructure/Features.mjs'
|
||||
import MockAnalyticsApiClass from './mocks/MockAnalyticsApi.mjs'
|
||||
import { expectValidationErrorRaw } from '@overleaf/validation-tools/testUtils.js'
|
||||
|
||||
const User = UserHelper.promises
|
||||
@@ -19,6 +20,14 @@ function privateApiRequest(options) {
|
||||
})
|
||||
}
|
||||
|
||||
let MockAnalyticsApi
|
||||
|
||||
before(function () {
|
||||
if (Features.hasFeature('saas')) {
|
||||
MockAnalyticsApi = MockAnalyticsApiClass.instance()
|
||||
}
|
||||
})
|
||||
|
||||
describe('AnalyticsController', function () {
|
||||
let owner
|
||||
|
||||
@@ -88,6 +97,81 @@ describe('AnalyticsController', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('GET /analytics/uniExternalCollaboration', function () {
|
||||
beforeEach(function () {
|
||||
// both the analytics API URL and its mock are saas-only, see
|
||||
// test/acceptance/config/settings.test.saas.js and Init.mjs
|
||||
if (!Features.hasFeature('saas')) {
|
||||
this.skip()
|
||||
}
|
||||
MockAnalyticsApi.reset()
|
||||
})
|
||||
|
||||
it('should return the data from the analytics service', async function () {
|
||||
const response = await privateApiRequest({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration?university_id=42',
|
||||
})
|
||||
expect(response.statusCode).to.equal(200)
|
||||
expect(response.body).to.deep.equal([
|
||||
{ university_id: 123, external_collaborations: 321 },
|
||||
])
|
||||
expect(
|
||||
MockAnalyticsApi.getLastUniExternalCollaborationRequest().query
|
||||
).to.deep.equal({ university_id: '42' })
|
||||
})
|
||||
|
||||
it('should reject a non-numeric university id', async function () {
|
||||
const response = await privateApiRequest({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration?university_id=not-a-number',
|
||||
})
|
||||
expectValidationErrorRaw(response, 400, 'university_id')
|
||||
})
|
||||
|
||||
it('should reject a non-positive university id', async function () {
|
||||
const response = await privateApiRequest({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration?university_id=0',
|
||||
})
|
||||
expectValidationErrorRaw(response, 400, 'university_id')
|
||||
})
|
||||
|
||||
it('should reject a missing university id', async function () {
|
||||
const response = await privateApiRequest({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration',
|
||||
})
|
||||
expectValidationErrorRaw(response, 400, 'university_id')
|
||||
})
|
||||
|
||||
it('should require private API auth', async function () {
|
||||
const response = await authedRequest.request({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration?university_id=42',
|
||||
json: true,
|
||||
})
|
||||
expect(response.statusCode).to.equal(401)
|
||||
})
|
||||
|
||||
it('should not route a sub-path to the analytics service', async function () {
|
||||
const response = await privateApiRequest({
|
||||
method: 'get',
|
||||
url: '/analytics/uniExternalCollaboration/extra?university_id=42',
|
||||
})
|
||||
expect(response.statusCode).to.equal(404)
|
||||
})
|
||||
|
||||
it('should not route other methods to the analytics service', async function () {
|
||||
await privateApiRequest({
|
||||
method: 'post',
|
||||
url: '/analytics/uniExternalCollaboration?university_id=42',
|
||||
})
|
||||
expect(MockAnalyticsApi.getLastUniExternalCollaborationRequest()).to.be
|
||||
.null
|
||||
})
|
||||
})
|
||||
|
||||
describe('POST /analytics/register-v-1-salesforce-mapping', function () {
|
||||
it('should accept a well-formed mapping', async function () {
|
||||
if (!Features.hasFeature('analytics')) {
|
||||
|
||||
@@ -8,6 +8,7 @@ class MockAnalyticsApi extends AbstractMockApi {
|
||||
this.lastSplitTestAssignmentsRequest = null
|
||||
this.lastSplitTestCalcRequest = null
|
||||
this.lastSplitTestEventsRequest = null
|
||||
this.lastUniExternalCollaborationRequest = null
|
||||
}
|
||||
|
||||
getLastGraphRequest() {
|
||||
@@ -26,6 +27,10 @@ class MockAnalyticsApi extends AbstractMockApi {
|
||||
return this.lastSplitTestEventsRequest
|
||||
}
|
||||
|
||||
getLastUniExternalCollaborationRequest() {
|
||||
return this.lastUniExternalCollaborationRequest
|
||||
}
|
||||
|
||||
applyRoutes() {
|
||||
this.app.get('/graphs/:graph', (req, res) => {
|
||||
// case 3: recorded verbatim for later assertion by acceptance tests
|
||||
@@ -80,6 +85,14 @@ class MockAnalyticsApi extends AbstractMockApi {
|
||||
this.lastSplitTestEventsRequest = { query: getRawReqInput(req).query }
|
||||
res.json({ 'editor-open': { source: ['ide-open'] } })
|
||||
})
|
||||
|
||||
this.app.get('/uniExternalCollaboration', (req, res) => {
|
||||
// case 3: recorded verbatim for later assertion by acceptance tests
|
||||
this.lastUniExternalCollaborationRequest = {
|
||||
query: getRawReqInput(req).query,
|
||||
}
|
||||
res.json([{ university_id: 123, external_collaborations: 321 }])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user