From c2484e9e3594ee502048af6413477c1e603288a9 Mon Sep 17 00:00:00 2001 From: Oana Andrisoaei Date: Thu, 22 Aug 2024 14:31:09 +0300 Subject: [PATCH] fix: type errors in tests --- .../snyk-ignore/snyk-ignore.spec.ts | 24 +++++++++++-------- .../unit/iac/cli-share-results.fixtures.ts | 3 ++- test/jest/unit/iac/cli-share-results.spec.ts | 2 +- .../unit/iac/process-results/policy.spec.ts | 2 +- test/jest/unit/lib/ecosystems/policy.spec.ts | 10 ++++---- test/jest/unit/lib/iac/drift/drift.spec.ts | 8 ++++++- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/test/jest/acceptance/snyk-ignore/snyk-ignore.spec.ts b/test/jest/acceptance/snyk-ignore/snyk-ignore.spec.ts index 3a1707fb1e..014f709363 100644 --- a/test/jest/acceptance/snyk-ignore/snyk-ignore.spec.ts +++ b/test/jest/acceptance/snyk-ignore/snyk-ignore.spec.ts @@ -139,13 +139,15 @@ describe('snyk ignore', () => { const policy = await loadPolicy(project.path()); - expect(policy.exclude.code).toHaveLength(1); - expect(!!policy.exclude.code[0]['**/deps/**/*.ts']).toBeTruthy(); + expect(policy.exclude?.code).toHaveLength(1); + expect(!!policy.exclude?.code[0]['**/deps/**/*.ts']).toBeTruthy(); // Fake creation date - policy.exclude.code[0]['**/deps/**/*.ts'].created = new Date( - '2089-12-24T00:00:00.000Z', - ); + if (policy.exclude) { + policy.exclude.code[0]['**/deps/**/*.ts'].created = new Date( + '2089-12-24T00:00:00.000Z', + ); + } expect(policy.exclude).toMatchObject({ code: [ @@ -184,13 +186,15 @@ describe('snyk ignore', () => { const policyAfter = await loadPolicy(project.path()); - expect(policyAfter.exclude.code).toHaveLength(1); - expect(!!policyAfter.exclude.code[0]['**/deps/**/*.ts']).toBeTruthy(); + expect(policyAfter.exclude?.code).toHaveLength(1); + expect(!!policyAfter.exclude?.code[0]['**/deps/**/*.ts']).toBeTruthy(); // Fake creation date - policyAfter.exclude.code[0]['**/deps/**/*.ts'].created = new Date( - '2089-12-24T00:00:00.000Z', - ); + if (policyAfter.exclude) { + policyAfter.exclude.code[0]['**/deps/**/*.ts'].created = new Date( + '2089-12-24T00:00:00.000Z', + ); + } expect(policyAfter.exclude).toMatchObject({ code: [ diff --git a/test/jest/unit/iac/cli-share-results.fixtures.ts b/test/jest/unit/iac/cli-share-results.fixtures.ts index 8fc4153008..ae31a2cd2d 100644 --- a/test/jest/unit/iac/cli-share-results.fixtures.ts +++ b/test/jest/unit/iac/cli-share-results.fixtures.ts @@ -120,6 +120,7 @@ export const expectedEnvelopeFormatterResults = [ name: 'projectA', policy: '', target: { + name: undefined, remoteUrl: 'http://github.com/snyk/cli.git', }, targetReference: undefined, @@ -173,7 +174,7 @@ export const expectedEnvelopeFormatterResultsWithPolicy = expectedEnvelopeFormat return { ...result, policy: `# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.25.0 +version: v1.25.1 # ignores vulnerabilities until expiry date; change duration by modifying expiry date ignore: SNYK-CC-TF-4: diff --git a/test/jest/unit/iac/cli-share-results.spec.ts b/test/jest/unit/iac/cli-share-results.spec.ts index 422b16b37c..5d9bddb7e7 100644 --- a/test/jest/unit/iac/cli-share-results.spec.ts +++ b/test/jest/unit/iac/cli-share-results.spec.ts @@ -7,7 +7,7 @@ import { } from './cli-share-results.fixtures'; import * as request from '../../../../src/lib/request/request'; import * as envelopeFormatters from '../../../../src/lib/iac/envelope-formatters'; -import { Policy } from '../../../../src/lib/policy/find-and-load-policy'; +import { Policy } from 'snyk-policy'; import * as snykPolicyLib from 'snyk-policy'; describe('CLI Share Results', () => { diff --git a/test/jest/unit/iac/process-results/policy.spec.ts b/test/jest/unit/iac/process-results/policy.spec.ts index 9c9551ce3b..c4617fdc2b 100644 --- a/test/jest/unit/iac/process-results/policy.spec.ts +++ b/test/jest/unit/iac/process-results/policy.spec.ts @@ -16,7 +16,7 @@ async function filterFixture(policyName: string) { // The policy library modifies its input. In order to write meaningful // assertions, deep-clone the original fixture. - const filtered = filterIgnoredIssues(policy, cloneDeep(fixture)); + const filtered = filterIgnoredIssues(policy || undefined, cloneDeep(fixture)); return { fixture: fixture, diff --git a/test/jest/unit/lib/ecosystems/policy.spec.ts b/test/jest/unit/lib/ecosystems/policy.spec.ts index 4b72c031b3..f7999eeff5 100644 --- a/test/jest/unit/lib/ecosystems/policy.spec.ts +++ b/test/jest/unit/lib/ecosystems/policy.spec.ts @@ -1,5 +1,5 @@ import { Issue, IssuesData } from '../../../../../src/lib/ecosystems/types'; -import { Policy } from '../../../../../src/lib/policy/find-and-load-policy'; +import { Policy } from 'snyk-policy'; import { SEVERITY } from '@snyk/fix/dist/types'; import { filterIgnoredIssues } from '../../../../../src/lib/ecosystems/policy'; @@ -59,7 +59,7 @@ describe('filterIgnoredIssues fn', () => { const [filteredIssues, filteredIssuesData] = filterIgnoredIssues( issues, issuesData, - policy as Policy, + (policy as unknown) as Policy, ); expect(filteredIssues).toEqual([ @@ -132,7 +132,7 @@ describe('filterIgnoredIssues fn', () => { const [filteredIssues, filteredIssuesData] = filterIgnoredIssues( issues, issuesData, - policy as Policy, + (policy as unknown) as Policy, ); expect(filteredIssues).toEqual(issues); @@ -165,7 +165,7 @@ describe('filterIgnoredIssues fn', () => { const [filteredIssues, filteredIssuesData] = filterIgnoredIssues( issues, issuesData, - policy as Policy, + (policy as unknown) as Policy, ); expect(filteredIssues).toEqual([]); @@ -202,7 +202,7 @@ describe('filterIgnoredIssues fn', () => { const [filteredIssues, filteredIssuesData] = filterIgnoredIssues( issues, issuesData, - policy as Policy, + (policy as unknown) as Policy, ); expect(filteredIssues).toEqual([]); diff --git a/test/jest/unit/lib/iac/drift/drift.spec.ts b/test/jest/unit/lib/iac/drift/drift.spec.ts index b37b9f3734..9781e8ebe0 100644 --- a/test/jest/unit/lib/iac/drift/drift.spec.ts +++ b/test/jest/unit/lib/iac/drift/drift.spec.ts @@ -17,7 +17,7 @@ import { import { addIacDriftAnalytics } from '../../../../../../src/cli/commands/test/iac/local-execution/analytics'; import * as analytics from '../../../../../../src/lib/analytics'; import * as snykPolicy from 'snyk-policy'; -import { Policy } from '../../../../../../src/lib/policy/find-and-load-policy'; +import { Policy } from 'snyk-policy'; import { DCTL_EXIT_CODES, driftctlVersion, @@ -296,6 +296,8 @@ describe('updateExcludeInPolicy', () => { 'policy-no-excludes.yml', {}, { + code: [], + global: [], 'iac-drift': [ 'aws_iam_user.test-driftctl2', 'aws_iam_access_key.AKIA5QYBVVD2Y6PBAAPY', @@ -358,6 +360,8 @@ describe('updateExcludeInPolicy', () => { 'exclude-missing': true, }, { + code: [], + global: [], 'iac-drift': [ 'aws_s3_bucket_policy.driftctl', 'aws_s3_bucket_notification.driftctl', @@ -371,6 +375,8 @@ describe('updateExcludeInPolicy', () => { 'exclude-unmanaged': true, }, { + code: [], + global: [], 'iac-drift': [ 'aws_iam_user.test-driftctl2', 'aws_iam_access_key.AKIA5QYBVVD2Y6PBAAPY',