import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { parseAppScopedAttachmentPath } from '../supabase/functions/_backend/plugin_runtime/utils/attachmentPath.ts' import { appDayTotals, appPathPatterns, billableReadFilter, APPS_PER_REQUEST, buildAppDaysQuery, buildZoneSettingsQuery, dayWindow, DEFAULT_HEADER_BYTES, GRAPHQL_ALIASES_PER_REQUEST, escapeLike, FILES_BANDWIDTH_EXCLUDED_HOST_SUFFIXES, FILES_BANDWIDTH_PATH_PREFIXES, FILES_BANDWIDTH_READ_PREFIXES, isBudgetDepleted, isQueryableAppId, lacksQueryFilter, ownedAppKey, parseAppDaysResponse, parseZoneBandwidthTags, parseZoneSettingsResponse, readZoneBandwidth, reconstructedBytes, resetZoneBandwidthCaches, usesZoneBandwidth, ZONE_GRAPHQL_URL, zoneAnalyticsToken, zoneKeepsDay, ZoneAnalyticsBudgetDepleted, } from '../supabase/functions/_backend/utils/zoneBandwidth.ts' const ZONE = '7fe39404d772c5a0b4444f5a0475a586' const ZONE_B = 'df17bdd2be16ca09f5232058ce5790ce' const ORG = '046a36ac-e03c-4590-9257-bd6c9dba9ee8' const ORG_B = '9d3c3b1a-1111-4222-8333-444455556666' /** SQL LIKE with `\\` as the escape character: the rule the GraphQL `_like` filter applies. */ function sqlLike(value: string, likePattern: string) { let source = '' for (let index = 0; index < likePattern.length; index++) { const char = likePattern[index]! if (char === '\\') { source += likePattern[++index]!.replace(/[.*+?^${}()|[\]\\/-]/g, '\\$&') continue } source += char === '%' ? '[\\s\\S]*' : char === '_' ? '[\\s\\S]' : char.replace(/[.*+?^${}()|[\]\\/-]/g, '\\$&') } return new RegExp(`^${source}$`).test(value) } const group = (date: string, count: number, edgeResponseBytes: number) => ({ count, sum: { edgeResponseBytes }, dimensions: { date } }) /** A mocked GraphQL answer for buildAppDaysQuery: one alias per app. */ function appDaysResponse(perApp: ReturnType[][]) { return { data: { viewer: { zones: [Object.fromEntries(perApp.map((groups, index) => [`a${index}`, groups]))] } }, errors: null } } const settings = (notOlderThan: number) => ({ data: { viewer: { zones: [{ settings: { httpRequestsAdaptiveGroups: { maxDuration: 2_764_800, notOlderThan } } }] } }, errors: null }) describe('zone bandwidth config', () => { afterEach(() => vi.unstubAllEnvs()) it('parses comma-separated zone tags and ignores anything else', () => { expect(parseZoneBandwidthTags(`${ZONE}, ${ZONE_B.toUpperCase()} ,${ZONE}`)).toEqual([ZONE, ZONE_B]) expect(parseZoneBandwidthTags('')).toEqual([]) expect(parseZoneBandwidthTags(undefined)).toEqual([]) expect(parseZoneBandwidthTags('capgo.app,"}')).toEqual([]) }) it('uses zone bandwidth only when FILES_BANDWIDTH_ZONE_TAGS is set', () => { // getEnv reads process.env under Node. const c = { env: {} } as any vi.stubEnv('FILES_BANDWIDTH_ZONE_TAGS', '') expect(usesZoneBandwidth(c)).toBe(false) vi.stubEnv('FILES_BANDWIDTH_ZONE_TAGS', `${ZONE},${ZONE_B}`) expect(usesZoneBandwidth(c)).toBe(true) }) it('prefers CF_ZONE_ANALYTICS_TOKEN over CF_ANALYTICS_TOKEN', () => { const c = { env: {} } as any vi.stubEnv('CF_ZONE_ANALYTICS_TOKEN', '') vi.stubEnv('CF_ANALYTICS_TOKEN', 'analytics') expect(zoneAnalyticsToken(c)).toBe('analytics') vi.stubEnv('CF_ZONE_ANALYTICS_TOKEN', 'zone') expect(zoneAnalyticsToken(c)).toBe('zone') }) }) describe('zone bandwidth queries', () => { it('filters each app on its attachment paths, eyeball GET 200/206 only', () => { const query = buildAppDaysQuery(ZONE, [ownedAppKey(ORG, 'com.a.app'), ownedAppKey(ORG, 'com.b.app')], dayWindow('2026-11-01')) expect(query).toContain(`zoneTag: "${ZONE}"`) expect(query).toContain(`a0: httpRequestsAdaptiveGroups(limit: 100, filter: { datetime_geq: "2026-11-01T00:00:00.000Z", datetime_lt: "2026-11-02T00:00:00.000Z", ${billableReadFilter(appPathPatterns(ORG, 'com.a.app'))} }`) expect(query).toContain('a1: httpRequestsAdaptiveGroups') expect(query.match(/requestSource: "eyeball", clientRequestHTTPMethodName: "GET", edgeResponseStatus_in: \[200, 206\]/g)).toHaveLength(2) expect(appPathPatterns(ORG, 'com.a.app')).toEqual([ `/files/read/attachments/orgs/${ORG}/apps/com.a.app/%`, `/private/files/read/attachments/orgs/${ORG}/apps/com.a.app/%`, `/files/upload/attachments/orgs/${ORG}/apps/com.a.app/%`, `/private/files/upload/attachments/orgs/${ORG}/apps/com.a.app/%`, ]) expect(FILES_BANDWIDTH_PATH_PREFIXES.slice(0, FILES_BANDWIDTH_READ_PREFIXES.length)).toEqual([...FILES_BANDWIDTH_READ_PREFIXES]) }) it('keeps only the reads the files handler counted', () => { const filter = billableReadFilter(['/p/%']) expect(filter).toContain('requestSource: "eyeball"') // A HEAD has no body. expect(filter).toContain('clientRequestHTTPMethodName: "GET"') expect(filter).toContain('edgeResponseStatus_in: [200, 206]') // device\_id is escaped in the GraphQL text (\\_), so `?deviceXid=d` cannot match. expect(filter).toContain(String.raw`{ OR: [{ clientRequestQuery_like: "?device\\_id=_%" }, { clientRequestQuery_like: "%&device\\_id=_%" }] }`) expect(filter).toContain(String.raw`{ clientRequestQuery_notlike: "?device\\_id=&%" }`) expect(filter).not.toContain('"?device_id=') for (const suffix of FILES_BANDWIDTH_EXCLUDED_HOST_SUFFIXES) expect(filter).toContain(`{ clientRequestHTTPHost_notlike: "%${suffix}" }`) expect(filter).toContain('OR: [{ clientRequestPath_like: "/p/%" }]') }) it('reads a zone without the device_id predicate when it cannot filter on the query', () => { expect(lacksQueryFilter({ data: null, errors: [{ message: 'zone \'x\' does not have access to the field \'clientrequestquery\' from the path' }] })).toBe(true) expect(lacksQueryFilter({ data: null, errors: [{ message: 'quota' }] })).toBe(false) const window = dayWindow('2026-11-01') expect(buildAppDaysQuery(ZONE, [ownedAppKey(ORG, 'a')], window, false)).not.toContain('clientRequestQuery') expect(buildAppDaysQuery(ZONE, [ownedAppKey(ORG, 'a')], window)).toContain('clientRequestQuery_like') }) it('refuses app IDs that could break out of the query or widen the LIKE', () => { for (const appId of ['com.a"} x', 'com.%', 'com a', '']) expect(isQueryableAppId(appId)).toBe(false) expect(isQueryableAppId('com.my_app-1.App')).toBe(true) expect(() => buildAppDaysQuery(ZONE, [ownedAppKey(ORG, 'com.%')], dayWindow('2026-11-01'))).toThrow('Unsafe app id') expect(() => buildAppDaysQuery(ZONE, [ownedAppKey('not-a-uuid', 'com.a')], dayWindow('2026-11-01'))).toThrow('Unsafe app id') }) it('matches an app ID with `_` exactly, never the app that differs only there', () => { expect(escapeLike('com.example.a_b')).toBe('com.example.a\\_b') expect(escapeLike('50%\\x')).toBe('50\\%\\\\x') const [pattern] = appPathPatterns(ORG, 'com.example.a_b') expect(pattern).toBe(`/files/read/attachments/orgs/${ORG}/apps/com.example.a\\_b/%`) expect(sqlLike(`/files/read/attachments/orgs/${ORG}/apps/com.example.a_b/x.zip`, pattern!)).toBe(true) expect(sqlLike(`/files/read/attachments/orgs/${ORG}/apps/com.example.aXb/x.zip`, pattern!)).toBe(false) // In the query the backslash survives GraphQL string escaping. const query = buildAppDaysQuery(ZONE, [ownedAppKey(ORG, 'com.example.a_b')], dayWindow('2026-11-01')) expect(query).toContain(`clientRequestPath_like: "/files/read/attachments/orgs/${ORG}/apps/com.example.a\\\\_b/%"`) }) it('anchors the app ID to the segment the files worker parses, with the exact org', () => { const [pattern] = appPathPatterns(ORG, 'com.a.app') const nested = `/files/read/attachments/orgs/${ORG}/apps/com.other.app/assets/apps/com.a.app/main.js` expect(sqlLike(nested, pattern!)).toBe(false) expect(parseAppScopedAttachmentPath(nested.slice('/files/read/attachments/'.length))).toMatchObject({ app_id: 'com.other.app' }) expect(sqlLike(`/files/read/attachments/orgs/${ORG_B}/apps/com.a.app/x.zip`, pattern!)).toBe(false) }) it('reads each zone\'s retention and skips days it no longer keeps', () => { const now = Date.parse('2026-11-29T02:30:00Z') expect(buildZoneSettingsQuery(ZONE)).toContain('httpRequestsAdaptiveGroups { maxDuration notOlderThan }') expect(parseZoneSettingsResponse(settings(7_776_000) as any)).toEqual({ maxDuration: 2_764_800, notOlderThan: 7_776_000 }) expect(() => parseZoneSettingsResponse({ data: { viewer: { zones: [{}] } }, errors: null })).toThrow('settings') // capgo.app: 90 days, the partial oldest day excluded. expect(zoneKeepsDay('2026-09-01', { maxDuration: 1, notOlderThan: 7_776_000 }, now)).toBe(true) expect(zoneKeepsDay('2026-08-31', { maxDuration: 1, notOlderThan: 7_776_000 }, now)).toBe(false) // usecapgo.com: 31 days. expect(zoneKeepsDay('2026-10-30', { maxDuration: 1, notOlderThan: 2_678_400 }, now)).toBe(true) expect(zoneKeepsDay('2026-10-29', { maxDuration: 1, notOlderThan: 2_678_400 }, now)).toBe(false) }) it('takes whole UTC days only', () => { expect(dayWindow('2026-12-31')).toEqual({ from: '2026-12-31T00:00:00.000Z', to: '2027-01-01T00:00:00.000Z' }) expect(() => dayWindow('2026-12-31T00:00:00Z')).toThrow('Invalid date') expect(() => dayWindow('soon')).toThrow('Invalid date') }) }) describe('zone bandwidth parsing', () => { it('sums each app per day across responses', () => { const reads = parseAppDaysResponse(appDaysResponse([[group('2026-11-01', 10, 50_000)], []]), ['com.a.app', 'com.b.app']) parseAppDaysResponse(appDaysResponse([[group('2026-11-01', 2, 5_000), group('2026-11-02', 1, 3_000)]]), ['com.a.app'], reads) expect(reads.get('com.a.app')).toEqual(new Map([['2026-11-01', { count: 12, edgeBytes: 55_000 }], ['2026-11-02', { count: 1, edgeBytes: 3_000 }]])) expect(reads.get('com.b.app')?.size).toBe(0) }) it('fails loudly on GraphQL errors, a missing zone or a missing alias', () => { expect(() => parseAppDaysResponse({ data: null, errors: [{ message: 'quota' }] }, ['com.a.app'])).toThrow('GraphQL: quota') expect(() => parseAppDaysResponse({ data: { viewer: { zones: [] } }, errors: null }, ['com.a.app'])).toThrow('no zone') expect(() => parseAppDaysResponse(appDaysResponse([[]]), ['com.a.app', 'com.b.app'])).toThrow('missing alias a1') }) it('recognises a depleted GraphQL budget, but not a query that is too big', () => { expect(isBudgetDepleted({ errors: [{ message: 'Rate limiter budget depleted. Please try again after 5 minutes.' }] }, 200)).toBe(true) expect(isBudgetDepleted(null, 429)).toBe(true) expect(isBudgetDepleted({ errors: [{ message: 'In combination, your request queries too many nodes, zones and accounts.' }] }, 200)).toBe(false) expect(isBudgetDepleted({ data: null, errors: null }, 200)).toBe(false) }) it('takes the header allowance off the edge bytes, never below zero', () => { expect(reconstructedBytes({ count: 10, edgeBytes: 100_000 })).toBe(100_000 - 10 * DEFAULT_HEADER_BYTES) expect(reconstructedBytes({ count: 10, edgeBytes: 1_000 })).toBe(0) expect(reconstructedBytes({ count: 2, edgeBytes: 10_000 }, 500)).toBe(9_000) }) it('sums an app over its owner orgs, and leaves out apps without reads', () => { const reads = new Map([ [ownedAppKey(ORG, 'com.a.app'), new Map([['2026-11-01', { count: 2, edgeBytes: 13_000 }]])], [ownedAppKey(ORG_B, 'com.a.app'), new Map([['2026-11-01', { count: 1, edgeBytes: 2_500 }]])], [ownedAppKey(ORG, 'com.b.app'), new Map()], [ownedAppKey(ORG, 'com.c.app'), new Map([['2026-10-31', { count: 1, edgeBytes: 9_000 }]])], ]) expect(appDayTotals(reads, '2026-11-01')).toEqual([{ app_id: 'com.a.app', date: '2026-11-01', bandwidth: 15_500 - 3 * DEFAULT_HEADER_BYTES }]) }) }) describe('readZoneBandwidth', () => { beforeEach(() => resetZoneBandwidthCaches()) const now = Date.parse('2026-11-29T10:00:00Z') const apps = [ownedAppKey(ORG, 'com.a.app'), ownedAppKey(ORG, 'com.b.app')] function mockFetch(handler: (zoneTag: string, query: string) => unknown) { return vi.fn(async (url: string | URL | Request, init: RequestInit) => { expect(String(url)).toBe(ZONE_GRAPHQL_URL) expect((init.headers as Record).Authorization).toBe('Bearer token') const { query } = JSON.parse(String(init.body)) as { query: string } const zoneTag = /zoneTag: "([0-9a-f]+)"/.exec(query)![1]! const answer = await handler(zoneTag, query) return answer instanceof Response ? answer : Response.json(answer) }) as unknown as typeof fetch & ReturnType } it('sums both zones per app, one request per zone after the settings', async () => { const fetchMock = mockFetch((zoneTag, query) => { if (query.includes('settings')) return settings(7_776_000) return zoneTag === ZONE ? appDaysResponse([[group('2026-11-28', 10, 1_015_000)], []]) : appDaysResponse([[group('2026-11-28', 2, 4_000)], [group('2026-11-28', 1, 1_000)]]) }) const rows = await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-11-28', apps, fetchMock, now) // com.b.app: 1,000 edge bytes, all headers. expect(rows).toEqual([ { app_id: 'com.a.app', date: '2026-11-28', bandwidth: 1_019_000 - 12 * DEFAULT_HEADER_BYTES }, { app_id: 'com.b.app', date: '2026-11-28', bandwidth: 0 }, ]) expect(fetchMock).toHaveBeenCalledTimes(4) // Settings are read once per isolate. await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-11-28', apps, fetchMock, now) expect(fetchMock).toHaveBeenCalledTimes(6) }) it('uses 10 GraphQL aliases per request', () => { expect(GRAPHQL_ALIASES_PER_REQUEST).toBe(10) }) it('splits more than 10 owner pairs into requests of 10 aliases and sums them all', async () => { const many = Array.from({ length: 11 }, (_, i) => ownedAppKey(ORG, `com.many${i}.app`)) const fetchMock = mockFetch((_zoneTag, query) => { if (query.includes('settings')) return settings(7_776_000) const aliases = (query.match(/ a\d+: /g) ?? []).length return appDaysResponse(Array.from({ length: aliases }, () => [group('2026-11-28', 1, 2_000)])) }) const rows = await readZoneBandwidth([ZONE], 'token', '2026-11-28', many, fetchMock, now) expect(rows).toHaveLength(11) const queries = fetchMock.mock.calls.map(call => JSON.parse(String((call[1] as RequestInit).body)).query as string).filter(query => !query.includes('settings')) expect(queries.map(query => (query.match(/ a\d+: /g) ?? []).length).sort()).toEqual([1, 10]) }) it('never opens more than six zone GraphQL connections at once', async () => { const many = Array.from({ length: 200 }, (_, i) => ownedAppKey(ORG, `com.many${i}.app`)) let inFlight = 0 let peak = 0 const fetchMock = mockFetch(async (_zoneTag, query) => { if (query.includes('settings')) return settings(7_776_000) inFlight++ peak = Math.max(peak, inFlight) await new Promise(resolve => setTimeout(resolve, 5)) inFlight-- const aliases = (query.match(/ a\d+: /g) ?? []).length return appDaysResponse(Array.from({ length: aliases }, () => [group('2026-11-28', 1, 2_000)])) }) const rows = await readZoneBandwidth([ZONE], 'token', '2026-11-28', many, fetchMock, now) expect(rows).toHaveLength(200) expect(peak).toBeLessThanOrEqual(6) expect(peak).toBe(6) }) async function queryFilterStageCounts(ownedPairs: string[]) { resetZoneBandwidthCaches() let active = 0 let stages = 0 let peakBatch = 0 const fetchMock = vi.fn(async (_url: string, init: RequestInit) => { const { query } = JSON.parse(String(init.body)) as { query: string } if (query.includes('settings')) return Response.json(settings(7_776_000)) if (active === 0) stages++ active++ peakBatch = Math.max(peakBatch, active) await new Promise(resolve => setTimeout(resolve, 1)) active-- if (query.includes('clientRequestQuery')) return Response.json({ data: null, errors: [{ message: 'zone does not have access to the field \'clientrequestquery\'' }] }) const aliases = (query.match(/ a\d+: /g) ?? []).length return Response.json(appDaysResponse(Array.from({ length: aliases }, () => [group('2026-11-28', 1, 2_000)]))) }) as unknown as typeof fetch await readZoneBandwidth([ZONE], 'token', '2026-11-28', ownedPairs, fetchMock, now) return { stages, peakBatch } } it('finishes a max-size job in at most three sequential GraphQL stages when the zone rejects query filters', async () => { const maxJob = Array.from({ length: APPS_PER_REQUEST }, (_, i) => ownedAppKey(ORG, `com.max${i}.app`)) const { stages, peakBatch } = await queryFilterStageCounts(maxJob) expect(peakBatch).toBe(Math.ceil(APPS_PER_REQUEST / GRAPHQL_ALIASES_PER_REQUEST)) expect(stages).toBeLessThanOrEqual(3) }) it('stays within six open GraphQL connections across two production zones', async () => { resetZoneBandwidthCaches() const maxJob = Array.from({ length: APPS_PER_REQUEST }, (_, i) => ownedAppKey(ORG, `com.twozone${i}.app`)) let inFlight = 0 let peak = 0 const fetchMock = vi.fn(async (_url: string, init: RequestInit) => { const { query } = JSON.parse(String(init.body)) as { query: string } if (query.includes('settings')) return Response.json(settings(7_776_000)) inFlight++ peak = Math.max(peak, inFlight) await new Promise(resolve => setTimeout(resolve, 1)) inFlight-- const aliases = (query.match(/ a\d+: /g) ?? []).length return Response.json(appDaysResponse(Array.from({ length: aliases }, () => [group('2026-11-28', 1, 2_000)]))) }) as unknown as typeof fetch await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-11-28', maxJob, fetchMock, now) expect(peak).toBeLessThanOrEqual(6) expect(peak).toBe(Math.min(6, Math.ceil(APPS_PER_REQUEST / GRAPHQL_ALIASES_PER_REQUEST) * 2)) }) it('keeps extra owner pairs within three stages on a zone rejecting query filters', async () => { const fortyApps = Array.from({ length: APPS_PER_REQUEST }, (_, i) => ownedAppKey(ORG, `com.extra${i}.app`)) const formerOwners = Array.from({ length: 5 }, (_, i) => ownedAppKey(ORG_B, `com.extra${i}.app`)) const fortyFivePairs = [...fortyApps, ...formerOwners] const { stages, peakBatch } = await queryFilterStageCounts(fortyFivePairs) expect(peakBatch).toBe(Math.ceil(fortyFivePairs.length / GRAPHQL_ALIASES_PER_REQUEST)) expect(stages).toBeLessThanOrEqual(3) }) it('retries a zone without the device_id predicate once, then remembers it', async () => { const queries: string[] = [] const fetchMock = mockFetch((zoneTag, query) => { if (query.includes('settings')) return settings(7_776_000) queries.push(`${zoneTag}:${query.includes('clientRequestQuery') ? 'device' : 'all'}`) if (zoneTag === ZONE_B && query.includes('clientRequestQuery')) return { data: null, errors: [{ message: 'zone does not have access to the field \'clientrequestquery\'' }] } return appDaysResponse([[group('2026-11-28', 1, 11_500)], []]) }) const rows = await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-11-28', apps, fetchMock, now) // com.b.app had no reads: a zero total, so an overwrite clears an older value. expect(rows).toEqual([ { app_id: 'com.a.app', date: '2026-11-28', bandwidth: 2 * (11_500 - DEFAULT_HEADER_BYTES) }, { app_id: 'com.b.app', date: '2026-11-28', bandwidth: 0 }, ]) expect(queries.sort()).toEqual([`${ZONE}:device`, `${ZONE_B}:all`, `${ZONE_B}:device`]) queries.length = 0 await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-11-28', apps, fetchMock, now) expect(queries.sort()).toEqual([`${ZONE}:device`, `${ZONE_B}:all`]) }) it('skips a zone that no longer keeps the day', async () => { const fetchMock = mockFetch((zoneTag, query) => { if (query.includes('settings')) return settings(zoneTag === ZONE ? 7_776_000 : 2_678_400) expect(zoneTag).toBe(ZONE) return appDaysResponse([[group('2026-10-01', 1, 2_500)], []]) }) expect(await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-10-01', apps, fetchMock, now)).toEqual([ { app_id: 'com.a.app', date: '2026-10-01', bandwidth: 1_000 }, { app_id: 'com.b.app', date: '2026-10-01', bandwidth: 0 }, ]) }) it('writes nothing for a day no zone keeps any more (unknown, not zero)', async () => { const fetchMock = mockFetch((_zoneTag, query) => { if (query.includes('settings')) return settings(2_678_400) throw new Error('no zone keeps the day: nothing to query') }) expect(await readZoneBandwidth([ZONE, ZONE_B], 'token', '2026-09-01', apps, fetchMock, now)).toEqual([]) }) it('throws on a depleted budget, an HTTP error or a GraphQL error, so the queue retries', async () => { const depleted = mockFetch((_zone, query) => query.includes('settings') ? settings(7_776_000) : { errors: [{ message: 'budget depleted' }] }) await expect(readZoneBandwidth([ZONE], 'token', '2026-11-28', apps, depleted, now)).rejects.toThrow(ZoneAnalyticsBudgetDepleted) resetZoneBandwidthCaches() const http = mockFetch(() => new Response('nope', { status: 500 })) await expect(readZoneBandwidth([ZONE], 'token', '2026-11-28', apps, http, now)).rejects.toThrow('HTTP 500') resetZoneBandwidthCaches() const failed = mockFetch((_zone, query) => query.includes('settings') ? settings(7_776_000) : { data: null, errors: [{ message: 'too many nodes' }] }) await expect(readZoneBandwidth([ZONE], 'token', '2026-11-28', apps, failed, now)).rejects.toThrow('GraphQL: too many nodes') }) it('sends nothing without a queryable app', async () => { const fetchMock = mockFetch(() => settings(7_776_000)) expect(await readZoneBandwidth([ZONE], 'token', '2026-11-28', [ownedAppKey(ORG, 'com.%')], fetchMock, now)).toEqual([]) expect(fetchMock).not.toHaveBeenCalled() }) })