Skip to content

Commit

Permalink
fix: type errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oana-andrisoaei-snyk authored and agatakrajewska committed Sep 2, 2024
1 parent 881fc19 commit c2484e9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
24 changes: 14 additions & 10 deletions test/jest/acceptance/snyk-ignore/snyk-ignore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
3 changes: 2 additions & 1 deletion test/jest/unit/iac/cli-share-results.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const expectedEnvelopeFormatterResults = [
name: 'projectA',
policy: '',
target: {
name: undefined,
remoteUrl: 'http://github.com/snyk/cli.git',
},
targetReference: undefined,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/jest/unit/iac/cli-share-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/jest/unit/iac/process-results/policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions test/jest/unit/lib/ecosystems/policy.spec.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -59,7 +59,7 @@ describe('filterIgnoredIssues fn', () => {
const [filteredIssues, filteredIssuesData] = filterIgnoredIssues(
issues,
issuesData,
policy as Policy,
(policy as unknown) as Policy,
);

expect(filteredIssues).toEqual([
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('filterIgnoredIssues fn', () => {
const [filteredIssues, filteredIssuesData] = filterIgnoredIssues(
issues,
issuesData,
policy as Policy,
(policy as unknown) as Policy,
);

expect(filteredIssues).toEqual([]);
Expand Down Expand Up @@ -202,7 +202,7 @@ describe('filterIgnoredIssues fn', () => {
const [filteredIssues, filteredIssuesData] = filterIgnoredIssues(
issues,
issuesData,
policy as Policy,
(policy as unknown) as Policy,
);

expect(filteredIssues).toEqual([]);
Expand Down
8 changes: 7 additions & 1 deletion test/jest/unit/lib/iac/drift/drift.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -296,6 +296,8 @@ describe('updateExcludeInPolicy', () => {
'policy-no-excludes.yml',
{},
{
code: [],
global: [],
'iac-drift': [
'aws_iam_user.test-driftctl2',
'aws_iam_access_key.AKIA5QYBVVD2Y6PBAAPY',
Expand Down Expand Up @@ -358,6 +360,8 @@ describe('updateExcludeInPolicy', () => {
'exclude-missing': true,
},
{
code: [],
global: [],
'iac-drift': [
'aws_s3_bucket_policy.driftctl',
'aws_s3_bucket_notification.driftctl',
Expand All @@ -371,6 +375,8 @@ describe('updateExcludeInPolicy', () => {
'exclude-unmanaged': true,
},
{
code: [],
global: [],
'iac-drift': [
'aws_iam_user.test-driftctl2',
'aws_iam_access_key.AKIA5QYBVVD2Y6PBAAPY',
Expand Down

0 comments on commit c2484e9

Please sign in to comment.