Skip to content

Commit e8529d9

Browse files
committed
test: fix request counts for new FF
1 parent 80179e4 commit e8529d9

File tree

3 files changed

+59
-91
lines changed

3 files changed

+59
-91
lines changed

test/jest/unit/pnpm/snyk-test-pnpm-project.spec.ts

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,24 @@ describe('snyk test for pnpm project', () => {
2626
jest.restoreAllMocks();
2727
});
2828

29+
const mockFeatureFlagResponseFn = () => {
30+
return Promise.resolve({
31+
res: { statusCode: 200 } as NeedleResponse,
32+
body: {
33+
code: 200,
34+
ok: true,
35+
},
36+
});
37+
}
38+
2939
describe('no local flag is used', () => {
3040
describe('project contains pnpm-lock.yaml file', () => {
3141
it('should scan pnpm vulnerabilities when enablePnpmCli feature flag is enabled', async () => {
3242
const fixturePath = getFixturePath('pnpm-app');
3343

34-
// this is for 'enablePnpmCli' feature flag
35-
mockedMakeRequest.mockImplementationOnce(() => {
36-
return Promise.resolve({
37-
res: { statusCode: 200 } as NeedleResponse,
38-
body: {
39-
code: 200,
40-
ok: true,
41-
},
42-
});
43-
});
44+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
45+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
46+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
4447

4548
mockedMakeRequest.mockImplementationOnce(() => {
4649
return Promise.resolve({
@@ -59,7 +62,7 @@ describe('snyk test for pnpm project', () => {
5962
_doubleDashArgs: [],
6063
});
6164

62-
expect(mockedMakeRequest).toHaveBeenCalledTimes(2);
65+
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
6366
expect(mockedMakeRequest).toHaveBeenCalledWith(
6467
expect.objectContaining({
6568
body: expect.objectContaining({
@@ -100,16 +103,9 @@ describe('snyk test for pnpm project', () => {
100103
it('should scan pnpm vulnerabilities as npm project when enablePnpmCli feature flag is not enabled', async () => {
101104
const fixturePath = getFixturePath('pnpm-app');
102105

103-
// this is for 'enablePnpmCli' feature flag
104-
mockedMakeRequest.mockImplementationOnce(() => {
105-
return Promise.resolve({
106-
res: { statusCode: 200 } as NeedleResponse,
107-
body: {
108-
code: 200,
109-
ok: false,
110-
},
111-
});
112-
});
106+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
107+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
108+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
113109

114110
mockedMakeRequest.mockImplementationOnce(() => {
115111
return Promise.resolve({
@@ -128,7 +124,7 @@ describe('snyk test for pnpm project', () => {
128124
_doubleDashArgs: [],
129125
});
130126

131-
expect(mockedMakeRequest).toHaveBeenCalledTimes(2);
127+
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
132128

133129
const expectedResultObject = {
134130
vulnerabilities: [],
@@ -166,16 +162,9 @@ describe('snyk test for pnpm project', () => {
166162
it('should scan pnpm workspace vulnerabilities', async () => {
167163
const fixturePath = getFixturePath('workspace-multi-type');
168164

169-
// this is for 'enablePnpmCli' feature flag
170-
mockedMakeRequest.mockImplementationOnce(() => {
171-
return Promise.resolve({
172-
res: { statusCode: 200 } as NeedleResponse,
173-
body: {
174-
code: 200,
175-
ok: true,
176-
},
177-
});
178-
});
165+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
166+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
167+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
179168

180169
mockedMakeRequest.mockImplementation(() => {
181170
return Promise.resolve({
@@ -195,7 +184,7 @@ describe('snyk test for pnpm project', () => {
195184
_doubleDashArgs: [],
196185
});
197186

198-
expect(mockedMakeRequest).toHaveBeenCalledTimes(11);
187+
expect(mockedMakeRequest).toHaveBeenCalledTimes(12);
199188

200189
const parsedResult = JSON.parse(result.getDisplayResults());
201190
const pnpmResult = parsedResult.filter(
@@ -209,16 +198,9 @@ describe('snyk test for pnpm project', () => {
209198
it('should not scan pnpm workspace vulnerabilities, only npm and yarn', async () => {
210199
const fixturePath = getFixturePath('workspace-multi-type');
211200

212-
// this is for 'enablePnpmCli' feature flag
213-
mockedMakeRequest.mockImplementationOnce(() => {
214-
return Promise.resolve({
215-
res: { statusCode: 200 } as NeedleResponse,
216-
body: {
217-
code: 200,
218-
ok: false,
219-
},
220-
});
221-
});
201+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
202+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
203+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
222204

223205
mockedMakeRequest.mockImplementation(() => {
224206
return Promise.resolve({
@@ -238,7 +220,7 @@ describe('snyk test for pnpm project', () => {
238220
_doubleDashArgs: [],
239221
});
240222

241-
expect(mockedMakeRequest).toHaveBeenCalledTimes(7);
223+
expect(mockedMakeRequest).toHaveBeenCalledTimes(8);
242224

243225
const parsedResult = JSON.parse(result.getDisplayResults());
244226
const pnpmResult = parsedResult.filter(

test/jest/unit/python/snyk-test-pyproject.spec.ts

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ describe('snyk test for python project', () => {
3131
jest.restoreAllMocks();
3232
});
3333

34+
const mockFeatureFlagResponseFn = () => {
35+
return Promise.resolve({
36+
res: { statusCode: 200 } as NeedleResponse,
37+
body: {
38+
code: 200,
39+
ok: true,
40+
},
41+
});
42+
}
43+
3444
describe('no flag is used', () => {
3545
describe('project contains pyproject.toml file', () => {
3646
it('should scan poetry vulnerabilities', async () => {
@@ -49,16 +59,10 @@ describe('snyk test for python project', () => {
4959
},
5060
};
5161

52-
// this is for 'enablePnpmCli' feature flag
53-
mockedMakeRequest.mockImplementationOnce(() => {
54-
return Promise.resolve({
55-
res: { statusCode: 200 } as NeedleResponse,
56-
body: {
57-
code: 200,
58-
ok: false,
59-
},
60-
});
61-
});
62+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
63+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
64+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
65+
6266
mockedLoadPlugin.mockImplementationOnce(() => {
6367
return plugin;
6468
});
@@ -82,7 +86,7 @@ describe('snyk test for python project', () => {
8286
expect(mockedLoadPlugin).toHaveBeenCalledTimes(1);
8387
expect(mockedLoadPlugin).toHaveBeenCalledWith('poetry');
8488

85-
expect(mockedMakeRequest).toHaveBeenCalledTimes(2);
89+
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
8690
expect(mockedMakeRequest).toHaveBeenCalledWith(
8791
expect.objectContaining({
8892
body: expect.objectContaining({
@@ -136,16 +140,10 @@ describe('snyk test for python project', () => {
136140
},
137141
};
138142

139-
// this is for 'enablePnpmCli' feature flag
140-
mockedMakeRequest.mockImplementationOnce(() => {
141-
return Promise.resolve({
142-
res: { statusCode: 200 } as NeedleResponse,
143-
body: {
144-
code: 200,
145-
ok: false,
146-
},
147-
});
148-
});
143+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
144+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
145+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
146+
149147
mockedLoadPlugin.mockImplementationOnce(() => {
150148
return plugin;
151149
});
@@ -169,7 +167,7 @@ describe('snyk test for python project', () => {
169167
expect(mockedLoadPlugin).toHaveBeenCalledTimes(1);
170168
expect(mockedLoadPlugin).toHaveBeenCalledWith('poetry');
171169

172-
expect(mockedMakeRequest).toHaveBeenCalledTimes(2);
170+
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
173171
expect(mockedMakeRequest).toHaveBeenCalledWith(
174172
expect.objectContaining({
175173
body: expect.objectContaining({
@@ -227,16 +225,10 @@ describe('snyk test for python project', () => {
227225
},
228226
};
229227

230-
// this is for 'enablePnpmCli' feature flag
231-
mockedMakeRequest.mockImplementationOnce(() => {
232-
return Promise.resolve({
233-
res: { statusCode: 200 } as NeedleResponse,
234-
body: {
235-
code: 200,
236-
ok: false,
237-
},
238-
});
239-
});
228+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
229+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
230+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
231+
240232
mockedLoadPlugin.mockImplementationOnce(() => {
241233
return plugin;
242234
});
@@ -261,7 +253,7 @@ describe('snyk test for python project', () => {
261253
expect(mockedLoadPlugin).toHaveBeenCalledTimes(1);
262254
expect(mockedLoadPlugin).toHaveBeenCalledWith('pip');
263255

264-
expect(mockedMakeRequest).toHaveBeenCalledTimes(2);
256+
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
265257
expect(mockedMakeRequest).toHaveBeenCalledWith(
266258
expect.objectContaining({
267259
body: expect.objectContaining({
@@ -329,16 +321,10 @@ describe('snyk test for python project', () => {
329321
},
330322
};
331323

332-
// this is for 'enablePnpmCli' feature flag
333-
mockedMakeRequest.mockImplementationOnce(() => {
334-
return Promise.resolve({
335-
res: { statusCode: 200 } as NeedleResponse,
336-
body: {
337-
code: 200,
338-
ok: false,
339-
},
340-
});
341-
});
324+
// this is for 'enablePnpmCli' and 'enableAdvancedPackageManagerDetection' feature flags
325+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
326+
mockedMakeRequest.mockImplementationOnce(mockFeatureFlagResponseFn);
327+
342328
mockedLoadPlugin
343329
.mockImplementationOnce(() => pipfilePythonPluginResponse)
344330
.mockImplementationOnce(() => pyprojectPythonPluginResponse);
@@ -364,7 +350,7 @@ describe('snyk test for python project', () => {
364350
expect(mockedLoadPlugin).toHaveBeenCalledWith('pip');
365351
expect(mockedLoadPlugin).toHaveBeenCalledWith('poetry');
366352

367-
expect(mockedMakeRequest).toHaveBeenCalledTimes(3);
353+
expect(mockedMakeRequest).toHaveBeenCalledTimes(4);
368354
expect(mockedMakeRequest).toHaveBeenCalledWith(
369355
expect.objectContaining({
370356
body: expect.objectContaining({

test/tap/monitor-target.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test('Make sure that target is sent correctly', async (t) => {
4848
.resolves('master');
4949

5050
const { data } = await getFakeServerRequestBody();
51-
t.ok(requestSpy.calledTwice, 'needle.request was not called twice');
51+
t.ok(requestSpy.calledThrice, 'needle.request was not called thrice');
5252
t.ok(!isEmpty(data.target), 'target passed to request');
5353
t.ok(
5454
!isEmpty(data.targetFileRelativePath),
@@ -75,7 +75,7 @@ test("Make sure it's not failing monitor for non git projects", async (t) => {
7575
const requestSpy = sinon.spy(requestLib, 'request');
7676
const { data } = await getFakeServerRequestBody();
7777

78-
t.ok(requestSpy.calledTwice, 'needle.request was not called twice');
78+
t.ok(requestSpy.calledThrice, 'needle.request was not called thrice');
7979
t.ok(isEmpty(data.target), 'empty target passed to request');
8080
t.match(
8181
data.targetFileRelativePath,
@@ -92,7 +92,7 @@ test("Make sure it's not failing if there is no remote configured", async (t) =>
9292
const requestSpy = sinon.spy(requestLib, 'request');
9393
const { data } = await getFakeServerRequestBody();
9494

95-
t.ok(requestSpy.calledTwice, 'needle.request was not called twice');
95+
t.ok(requestSpy.calledThrice, 'needle.request was not called thrice');
9696
t.ok(isEmpty(data.target), 'empty target passed to request');
9797
t.match(
9898
data.targetFileRelativePath,

0 commit comments

Comments
 (0)