Skip to content

Commit

Permalink
Merge pull request #307 from github/latest-deployments-pagination
Browse files Browse the repository at this point in the history
Latest Deployments Pagination
  • Loading branch information
GrantBirki authored Sep 24, 2024
2 parents 409f6de + e583b76 commit ef4f017
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 97 deletions.
133 changes: 127 additions & 6 deletions __tests__/functions/deployment.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {
createDeploymentStatus,
latestDeployment,
latestActiveDeployment,
activeDeployment
} from '../../src/functions/deployment'
import * as core from '@actions/core'

var octokit
var context
var mockDeploymentData
var mockDeploymentResults
beforeEach(() => {
jest.clearAllMocks()
jest.spyOn(core, 'debug').mockImplementation(() => {})
process.env.GITHUB_SERVER_URL = 'https://github.com'

context = {
Expand Down Expand Up @@ -47,7 +49,11 @@ beforeEach(() => {
oid: '315cec138fc9d7dac8a47c6bba4217d3965ede3b'
}
}
]
],
pageInfo: {
endCursor: null,
hasNextPage: false
}
}
}
}
Expand Down Expand Up @@ -118,9 +124,9 @@ test('creates an in_progress deployment status', async () => {
test('successfully fetches the latest deployment', async () => {
octokit = createMockGraphQLOctokit(mockDeploymentData)

expect(await latestDeployment(octokit, context, environment)).toStrictEqual(
mockDeploymentResults
)
expect(
await latestActiveDeployment(octokit, context, environment)
).toStrictEqual(mockDeploymentResults)

expect(octokit.graphql).toHaveBeenCalled()
})
Expand All @@ -134,11 +140,126 @@ test('returns null if no deployments are found', async () => {
}
})

expect(await latestDeployment(octokit, context, environment)).toBeNull()
expect(await latestActiveDeployment(octokit, context, environment)).toBeNull()

expect(octokit.graphql).toHaveBeenCalled()
})

test('returns null if no deployments are found in 3 pages of queries', async () => {
octokit.graphql = jest
.fn()
.mockReturnValueOnce({
repository: {
deployments: {
nodes: [
{
state: 'INACTIVE'
}
],
pageInfo: {
endCursor: 'cursor',
hasNextPage: true
}
}
}
})
.mockReturnValueOnce({
repository: {
deployments: {
nodes: [
{
state: 'INACTIVE'
}
],
pageInfo: {
endCursor: 'cursor',
hasNextPage: true
}
}
}
})
.mockReturnValueOnce({
repository: {
deployments: {
nodes: [
{
state: 'INACTIVE'
}
],
pageInfo: {
endCursor: 'cursor',
hasNextPage: false
}
}
}
})

expect(await latestActiveDeployment(octokit, context, environment)).toBeNull()

expect(octokit.graphql).toHaveBeenCalledTimes(3)
})

test('returns the deployment when it is found in the second page of queries', async () => {
octokit.graphql = jest
.fn()
.mockReturnValueOnce({
repository: {
deployments: {
nodes: [
{
state: 'INACTIVE'
},
{
state: 'INACTIVE'
},
{
state: 'INACTIVE'
},
{
state: 'PENDING'
}
],
pageInfo: {
endCursor: 'cursor',
hasNextPage: true
}
}
}
})
.mockReturnValueOnce({
repository: {
deployments: {
nodes: [
{
state: 'INACTIVE'
},
{
state: 'INACTIVE'
},
{
state: 'ACTIVE'
},
{
state: 'INACTIVE'
}
],
pageInfo: {
endCursor: 'cursor',
hasNextPage: true
}
}
}
})

expect(
await latestActiveDeployment(octokit, context, environment)
).toStrictEqual({
state: 'ACTIVE'
})

expect(octokit.graphql).toHaveBeenCalledTimes(2)
})

test('returns false if the deployment is not active', async () => {
mockDeploymentData.repository.deployments.nodes[0].state = 'INACTIVE'
octokit = createMockGraphQLOctokit(mockDeploymentData)
Expand Down
138 changes: 93 additions & 45 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit ef4f017

Please sign in to comment.