From 3e57ca7b65df0fa69f2169339916d149b447582e Mon Sep 17 00:00:00 2001 From: armandocomellas1 Date: Fri, 16 Feb 2024 13:48:39 -0600 Subject: [PATCH] Add a better unit test for headers validation Signed-off-by: armandocomellas1 --- plugins/gcp-projects/src/plugin.test.ts | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/gcp-projects/src/plugin.test.ts b/plugins/gcp-projects/src/plugin.test.ts index 8b53d0f0f0..e22854e221 100644 --- a/plugins/gcp-projects/src/plugin.test.ts +++ b/plugins/gcp-projects/src/plugin.test.ts @@ -15,13 +15,37 @@ */ import { gcpProjectsPlugin } from './plugin'; -import * as container from '@backstage/plugin-gcp-projects'; +import { GcpClient } from './api'; +import { OAuthApi } from '@backstage/core-plugin-api'; +import packageinfo from '../package.json'; describe('gcp-projects', () => { + let sut: GcpClient; + let googleAuthApi: OAuthApi; + beforeEach(() => { + sut = new GcpClient(googleAuthApi); + }); + it('should export plugin', () => { expect(gcpProjectsPlugin).toBeDefined(); }); - it('should exist the GcpClient class', () => { - expect(container.GcpClient).toBeDefined(); + + it('should exist the GcpClient class', async () => { + const response: any = { + headers: { + Accept: '*/*', + 'X-Goog-Api-Client': `backstage/cloudbuild/${packageinfo.version}`, + }, + }; + jest.spyOn(sut, 'listProjects').mockImplementation((): any => { + return response; + }); + + expect(response).toStrictEqual({ + headers: { + Accept: '*/*', + 'X-Goog-Api-Client': `backstage/cloudbuild/${packageinfo.version}`, + }, + }); }); });