fix: Add missing header and use correct endpoint host (#23982)

This commit is contained in:
Stokes Player
2022-09-26 18:26:33 -04:00
committed by GitHub
parent 6a40936604
commit 3aad5a03e9
3 changed files with 21 additions and 3 deletions

View File

@@ -10,7 +10,11 @@ interface CollectableEvent {
cohort?: string
}
const cloudEnv = (process.env.CYPRESS_INTERNAL_EVENT_COLLECTOR_ENV || 'staging') as 'development' | 'staging' | 'production'
/**
* Defaults to staging when doing development. To override to production for development,
* explicitly set process.env.CYPRESS_INTERNAL_ENV to 'production`
*/
const cloudEnv = (process.env.CYPRESS_INTERNAL_EVENT_COLLECTOR_ENV || 'production') as 'development' | 'staging' | 'production'
export class EventCollectorActions {
constructor (private ctx: DataContext) {
@@ -23,7 +27,11 @@ export class EventCollectorActions {
await this.ctx.util.fetch(
`${dashboardUrl}/anon-collect`,
{ method: 'POST', body: JSON.stringify(event) },
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(event),
},
)
debug(`Recorded event: %o`, event)

View File

@@ -32,7 +32,7 @@ describe('EventCollectorActions', () => {
expect(ctx.util.fetch).to.have.been.calledOnceWith(
sinon.match(/anon-collect$/), // Verify URL ends with expected 'anon-collect' path
{ method: 'POST', body: '{"campaign":"abc","medium":"def","messageId":"ghi","cohort":"123"}' },
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{"campaign":"abc","medium":"def","messageId":"ghi","cohort":"123"}' },
)
})

View File

@@ -8,6 +8,16 @@ declare global {
}
}
/**
* Gulp is only used for running the application during development. At this point of starting the app,
* process.env.CYPRESS_INTERNAL_ENV has not been set yet unless explicitly set on the command line. If not
* set on the command line, it is set to 'development' [here](https://github.com/cypress-io/cypress/blob/a5ec234005fead97f6cfdf611abf8d9f4ad0565d/packages/server/lib/environment.js#L22)
*
* When running in a production build, a file is written out to set CYPRESS_INTERNAL_ENV to 'production'
* [here](https://github.com/cypress-io/cypress/blob/a5ec234005fead97f6cfdf611abf8d9f4ad0565d/scripts/binary/build.ts#L176).
* However, running in production will not use the code in this file.
*/
export const DEFAULT_INTERNAL_CLOUD_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production'
export const DEFAULT_INTERNAL_EVENT_COLLECTOR_ENV = process.env.CYPRESS_INTERNAL_ENV || 'staging'