From 45eab632937cc760b7181ea76753abbca0223d4b Mon Sep 17 00:00:00 2001 From: Smitha Borkar <12040799+smithaborkar@users.noreply.github.com> Date: Tue, 7 Jun 2022 12:30:49 -0700 Subject: [PATCH] WIP on index tests --- src/index.test.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/index.test.js diff --git a/src/index.test.js b/src/index.test.js new file mode 100644 index 0000000..d0b0870 --- /dev/null +++ b/src/index.test.js @@ -0,0 +1,39 @@ +const core = require('@actions/core') +const path = require('path') +const cp = require('child_process') +const nock = require('nock') +const axios = require('axios') +const { expect, jest } = require('@jest/globals') + +describe('GET', () => { + beforeAll(() => { + process.env.GITHUB_REPOSITORY = 'paper-spa/is-awesome' + process.env.GITHUB_TOKEN = 'gha-token' + + jest.spyOn(core, 'setOutput').mockImplementation(param => { + return param + }) + + jest.spyOn(core, 'setFailed').mockImplementation(param => { + return param + }) + // Mock error/warning/info/debug + jest.spyOn(core, 'error').mockImplementation(jest.fn()) + jest.spyOn(core, 'warning').mockImplementation(jest.fn()) + jest.spyOn(core, 'info').mockImplementation(jest.fn()) + jest.spyOn(core, 'debug').mockImplementation(jest.fn()) + }) + + + it('can successfully get the page', async () => { + + process.env.GITHUB_SHA = 'valid-build-version' + const fakeJwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w' + const scope = nock(`http://my-url`) + .get('/_apis/') + .reply(200, { value: [{ url: 'https://fake-artifact.com' }] }) + + + axios.get = jest.fn().mockResolvedValue('test') + + }