From d93b1abed0f3c649210bc4b2c5c39e249bc27790 Mon Sep 17 00:00:00 2001 From: "liad.shachoach" Date: Fri, 10 Jan 2025 17:12:09 +0200 Subject: [PATCH] validating that the fetch function is called with the correct body, excluding the headers to avoid exposing secrets in the tests Signed-off-by: liad.shachoach --- ...ketCloudBranchRestriction.examples.test.ts | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/plugins/scaffolder-backend-module-bitbucket-cloud/src/actions/bitbucketCloudBranchRestriction.examples.test.ts b/plugins/scaffolder-backend-module-bitbucket-cloud/src/actions/bitbucketCloudBranchRestriction.examples.test.ts index 4897d6acbf..0051ee511a 100644 --- a/plugins/scaffolder-backend-module-bitbucket-cloud/src/actions/bitbucketCloudBranchRestriction.examples.test.ts +++ b/plugins/scaffolder-backend-module-bitbucket-cloud/src/actions/bitbucketCloudBranchRestriction.examples.test.ts @@ -65,7 +65,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { expect(global.fetch).toHaveBeenCalledWith( 'https://api.bitbucket.org/2.0/repositories/workspace/repo/branch-restrictions', - { + expect.objectContaining({ body: JSON.stringify({ branch_match_kind: 'branching_model', users: [{ uuid: '{a-b-c-d}' }, { uuid: '{e-f-g-h}' }], @@ -74,13 +74,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { branch_type: 'development', }), method: 'POST', - headers: { - Accept: 'application/json', - Authorization: - 'Basic eC10b2tlbi1hdXRoOnlvdXItZGVmYXVsdC1hdXRoLXRva2Vu', - 'Content-Type': 'application/json', - }, - }, + }), ); }); @@ -91,7 +85,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { expect(global.fetch).toHaveBeenCalledWith( 'https://api.bitbucket.org/2.0/repositories/workspace/repo/branch-restrictions', - { + expect.objectContaining({ body: JSON.stringify({ branch_match_kind: 'branching_model', users: [], @@ -100,13 +94,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { branch_type: 'development', }), method: 'POST', - headers: { - Accept: 'application/json', - Authorization: - 'Basic eC10b2tlbi1hdXRoOnlvdXItZGVmYXVsdC1hdXRoLXRva2Vu', - 'Content-Type': 'application/json', - }, - }, + }), ); }); @@ -117,7 +105,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { expect(global.fetch).toHaveBeenCalledWith( 'https://api.bitbucket.org/2.0/repositories/workspace/repo/branch-restrictions', - { + expect.objectContaining({ body: JSON.stringify({ branch_match_kind: 'glob', kind: 'require_passing_builds_to_merge', @@ -125,13 +113,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { pattern: 'test-feature/*', }), method: 'POST', - headers: { - Accept: 'application/json', - Authorization: - 'Basic eC10b2tlbi1hdXRoOnlvdXItZGVmYXVsdC1hdXRoLXRva2Vu', - 'Content-Type': 'application/json', - }, - }, + }), ); }); @@ -142,7 +124,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { expect(global.fetch).toHaveBeenCalledWith( 'https://api.bitbucket.org/2.0/repositories/workspace/repo/branch-restrictions', - { + expect.objectContaining({ body: JSON.stringify({ branch_match_kind: 'glob', kind: 'require_approvals_to_merge', @@ -150,13 +132,7 @@ describe('bitbucketCloud:branchRestriction:create', () => { pattern: 'test-feature/*', }), method: 'POST', - headers: { - Accept: 'application/json', - Authorization: - 'Basic eC10b2tlbi1hdXRoOnlvdXItZGVmYXVsdC1hdXRoLXRva2Vu', - 'Content-Type': 'application/json', - }, - }, + }), ); }); });