From 510db159075acac11333138dfc9296dc287f4a7d Mon Sep 17 00:00:00 2001 From: Ankush Gupta Date: Fri, 24 Sep 2021 12:31:30 -0700 Subject: [PATCH] test: add tests for new environment and commithash functionality --- test/cloudflare.test.js | 152 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/test/cloudflare.test.js b/test/cloudflare.test.js index 2a8d545..23f684b 100644 --- a/test/cloudflare.test.js +++ b/test/cloudflare.test.js @@ -96,6 +96,158 @@ test('getDeploymentUrl() should fail if there are no deployments', async () => { ).rejects.toThrow() }) +test('getDeploymentUrl() should check all environments when null', async () => { + const data = { + data: { + result: [ + { + environment: 'production', + url: 'https://main.cf-project.pages.dev', + deployment_trigger: { + type: 'github:push', + metadata: { + branch: 'main' + } + }, + latest_stage: { + name: 'deploy', + status: 'success' + }, + source: { + type: 'github', + config: { + repo_name: 'website', + production_branch: 'main' + } + } + }, + { + environment: 'preview', + url: 'https://123.cf-project.pages.dev', + deployment_trigger: { + type: 'github:push', + metadata: { + branch: 'fix/test-1' + } + }, + latest_stage: { + name: 'deploy', + status: 'success' + }, + source: { + type: 'github', + config: { + repo_name: 'website' + } + } + } + ] + } + } + axios.get.mockResolvedValueOnce(data) + + const { url } = await getDeploymentUrl( + '123xyz', + 'zentered', + 'user@example.com', + 'cf-project', + 'website', + 'main', + null, + null + ) + + expect(url).toEqual('https://main.cf-project.pages.dev') +}) + +test('getDeploymentUrl() should filter by commitHash when provided', async () => { + const data = { + data: { + result: [ + { + environment: 'production', + url: 'https://main-123.cf-project.pages.dev', + deployment_trigger: { + type: 'github:push', + metadata: { + branch: 'main', + commit_hash: '123' + } + }, + latest_stage: { + name: 'deploy', + status: 'success' + }, + source: { + type: 'github', + config: { + repo_name: 'website', + production_branch: 'main' + } + } + }, + { + environment: 'production', + url: 'https://main-456.cf-project.pages.dev', + deployment_trigger: { + type: 'github:push', + metadata: { + branch: 'main', + commit_hash: '456' + } + }, + latest_stage: { + name: 'deploy', + status: 'success' + }, + source: { + type: 'github', + config: { + repo_name: 'website', + production_branch: 'main' + } + } + }, + { + environment: 'preview', + url: 'https://789.cf-project.pages.dev', + deployment_trigger: { + type: 'github:push', + metadata: { + branch: 'fix/test-1', + commit_hash: '789' + } + }, + latest_stage: { + name: 'deploy', + status: 'success' + }, + source: { + type: 'github', + config: { + repo_name: 'website' + } + } + } + ] + } + } + axios.get.mockResolvedValueOnce(data) + + const { url } = await getDeploymentUrl( + '123xyz', + 'zentered', + 'user@example.com', + 'cf-project', + 'website', + 'main', + null, + '456' + ) + + expect(url).toEqual('https://main-456.cf-project.pages.dev') +}) + test('getDeploymentUrl() should fail if there are no matching builds', async () => { const data = { data: {