import { HTTPTransport } from '../../src/transports' ; import { AMPLITUDE_SERVER_URL } from '../../src/constants' ; import { Transport , Payload , Status , Response } from '@amplitude/types' ; export class TestTransport extends HTTPTransport { public constructor ( ) { super ( { serverUrl : AMPLITUDE_SERVER_URL , headers : { 'Content-Type' : 'application/json' , } , requestTimeoutMillis : 10000 , } ) ; } public async sendDummyPayload ( ) { return await this . sendPayload ( { api_key : 'NOT_A_REAL_API_KEY' , events : [ ] , options : { } , } ) ; } } const DEFAULT_RESPONSE_BODY = { status : Status . RateLimit , statusCode : 429 , body : { error : 'NOT_A_REAL_ERROR' , epsThreshold : 0 , throttledDevices : { } , throttledUsers : { } , exceededDailyQuotaDevices : { } , exceededDailyQuotaUsers : { } , throttledEvents : [ ] , } , } ; export class MockTransport implements Transport { private readonly _failingId : string ; private readonly _response : Response ; public failCount = 0 ; public passCount = 0 ; public constructor ( failingId , response ) { this . _failingId = failingId ; this . _response = response ?? DEFAULT_RESPONSE_BODY ; } public async sendPayload ( payload ) { const isMatch = payload . events . some ( event => event . user_id === this . _failingId ) ; if ( isMatch ) { this . failCount += 1 ; return Promise . resolve ( this . _response ) ; } else { this . passCount += 1 ; return Promise . resolve ( { status : Status . Success , statusCode : 200 } ) ; } } }