|
1 | 1 | import { resetUrlsMock, urlsMockFns } from '@sim/testing' |
2 | 2 | import { createRouteContext } from '@sim/testing/helpers/http' |
3 | 3 | import { authInternalMock, authInternalMockFns } from '@sim/testing/mocks/auth-internal.mock' |
| 4 | +import { resetEnvMock, setEnv } from '@sim/testing/mocks/env.mock' |
4 | 5 | import { hybridAuthMockFns } from '@sim/testing/mocks/hybrid-auth.mock' |
5 | 6 | import { utilsHelpersMock, utilsHelpersMockFns } from '@sim/testing/mocks/utils-helpers.mock' |
6 | 7 | import { NextRequest } from 'next/server' |
7 | | -import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest' |
| 8 | +import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
8 | 9 |
|
9 | 10 | afterAll(resetUrlsMock) |
10 | 11 |
|
@@ -170,3 +171,34 @@ describe('maskPIIBatchViaHttp', () => { |
170 | 171 | }) |
171 | 172 | }) |
172 | 173 | }) |
| 174 | + |
| 175 | +describe('maskPIIBatchViaHttp with PII_MASK_CHUNK_CONCURRENCY set', () => { |
| 176 | + afterEach(() => { |
| 177 | + resetEnvMock() |
| 178 | + vi.resetModules() |
| 179 | + }) |
| 180 | + |
| 181 | + it('masks when the deployment sets the chunk concurrency (env values arrive as strings)', async () => { |
| 182 | + mockToken.mockResolvedValue('tok') |
| 183 | + mockBaseUrl.mockReturnValue('http://app.internal:3000') |
| 184 | + vi.stubGlobal( |
| 185 | + 'fetch', |
| 186 | + vi.fn(async (_url: string, init: { body: string }) => { |
| 187 | + const { texts } = JSON.parse(init.body) as { texts: string[] } |
| 188 | + return new Response(JSON.stringify({ masked: texts.map((t) => `M(${t})`) }), { |
| 189 | + status: 200, |
| 190 | + headers: { 'content-type': 'application/json' }, |
| 191 | + }) |
| 192 | + }) |
| 193 | + ) |
| 194 | + setEnv({ PII_MASK_CHUNK_CONCURRENCY: '8' }) |
| 195 | + vi.resetModules() |
| 196 | + const { maskPIIBatchViaHttp: maskWithConfiguredConcurrency } = await import( |
| 197 | + '@/lib/guardrails/mask-client' |
| 198 | + ) |
| 199 | + |
| 200 | + const { masked } = await maskWithConfiguredConcurrency(['a', 'b'], []) |
| 201 | + |
| 202 | + expect(masked).toEqual(['M(a)', 'M(b)']) |
| 203 | + }) |
| 204 | +}) |
0 commit comments