Skip to content

Commit 0d65e06

Browse files
committed
Add feature flag
1 parent 1864c3b commit 0d65e06

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

node/services/product.test.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { fetchProduct } from './product'
2+
import { createContext } from '../mocks/contextFactory'
3+
4+
// Mock the compareApiResults function
5+
jest.mock('../utils/compareResults', () => ({
6+
compareApiResults: jest.fn().mockImplementation((func1) => func1())
7+
}))
8+
9+
describe('fetchProduct service', () => {
10+
const mockProduct = {
11+
productId: 'test-product',
12+
productName: 'Test Product',
13+
brand: 'Test Brand',
14+
}
15+
16+
beforeEach(() => {
17+
jest.clearAllMocks()
18+
})
19+
20+
it('should use intsch directly for b2bstoreqa account', async () => {
21+
const ctx = createContext({
22+
accountName: 'b2bstoreqa',
23+
})
24+
25+
// Mock the intsch client to return a product
26+
ctx.clients.intsch.fetchProduct = jest.fn().mockResolvedValue(mockProduct)
27+
28+
const args = {
29+
identifier: { field: 'id' as const, value: 'test-id' },
30+
salesChannel: 1,
31+
}
32+
33+
const result = await fetchProduct(ctx as any, args)
34+
35+
expect(ctx.clients.intsch.fetchProduct).toHaveBeenCalled()
36+
expect(result).toEqual([mockProduct])
37+
})
38+
39+
it('should use intsch directly for biggy account', async () => {
40+
const ctx = createContext({
41+
accountName: 'biggy',
42+
})
43+
44+
// Mock the intsch client to return a product
45+
ctx.clients.intsch.fetchProduct = jest.fn().mockResolvedValue(mockProduct)
46+
47+
const args = {
48+
identifier: { field: 'id' as const, value: 'test-id' },
49+
salesChannel: 1,
50+
}
51+
52+
const result = await fetchProduct(ctx as any, args)
53+
54+
expect(ctx.clients.intsch.fetchProduct).toHaveBeenCalled()
55+
expect(result).toEqual([mockProduct])
56+
})
57+
58+
it('should use compareApiResults for other accounts', async () => {
59+
const { compareApiResults } = require('../utils/compareResults')
60+
const ctx = createContext({
61+
accountName: 'regularaccount',
62+
})
63+
64+
// Mock the search client by casting to any
65+
;(ctx.clients as any).search = {
66+
productById: jest.fn().mockResolvedValue([mockProduct])
67+
}
68+
69+
const args = {
70+
identifier: { field: 'id' as const, value: 'test-id' },
71+
salesChannel: 1,
72+
}
73+
74+
await fetchProduct(ctx as any, args)
75+
76+
expect(compareApiResults).toHaveBeenCalled()
77+
})
78+
})

node/services/product.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,22 @@ export function buildVtexSegment({
142142
/**
143143
* Main product fetching function with compareApiResults implementation
144144
* Uses search client as primary and intsch.fetchProduct as secondary
145+
* For specific accounts, skips comparison and uses intsch directly
145146
*/
146147
export async function fetchProduct(
147148
ctx: Context,
148149
args: FetchProductArgs
149150
): Promise<SearchProduct[]> {
150151
const COMPARISON_SAMPLE_RATE = ctx.vtex.production ? 1 : 100 // 1% of requests will be compared in prod and 100% in dev
151152

153+
// List of accounts that should use intsch directly without comparison
154+
const INTSCH_ONLY_ACCOUNTS = ['b2bstoreqa', 'biggy', 'diegob2b', 'intelbras']
155+
156+
// Check if current account should skip comparison and use intsch directly
157+
if (INTSCH_ONLY_ACCOUNTS.includes(ctx.vtex.account)) {
158+
return fetchProductFromIntsch(ctx, args)
159+
}
160+
152161
return compareApiResults(
153162
() => fetchProductFromSearch(ctx, args),
154163
() => fetchProductFromIntsch(ctx, args),

0 commit comments

Comments
 (0)