Skip to content

Commit

Permalink
test: add tests for new environment and commithash functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushg committed Sep 24, 2021
1 parent 8d50387 commit 510db15
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions test/cloudflare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 510db15

Please sign in to comment.