mirror of
https://github.com/actions/configure-pages.git
synced 2025-12-08 16:16:09 +00:00
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
const core = require('@actions/core')
|
|
const axios = require('axios')
|
|
|
|
const enablePages = require('./enable-pages')
|
|
|
|
describe('enablePages', () => {
|
|
const GITHUB_REPOSITORY = 'paper-spa/is-awesome'
|
|
const GITHUB_TOKEN = 'gha-token'
|
|
|
|
beforeEach(() => {
|
|
jest.restoreAllMocks()
|
|
|
|
// 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('makes a request to create a page', async () => {
|
|
jest.spyOn(axios, 'post').mockImplementationOnce(() => Promise.resolve({}))
|
|
|
|
await enablePages({
|
|
repositoryNwo: GITHUB_REPOSITORY,
|
|
githubToken: GITHUB_TOKEN
|
|
})
|
|
})
|
|
|
|
it('handles a 409 response when the page already exists', async () => {
|
|
jest
|
|
.spyOn(axios, 'post')
|
|
.mockImplementationOnce(() => Promise.reject({response: {status: 409}}))
|
|
|
|
// Simply assert that no error is raised
|
|
await enablePages({
|
|
repositoryNwo: GITHUB_REPOSITORY,
|
|
githubToken: GITHUB_TOKEN
|
|
})
|
|
})
|
|
|
|
it('re-raises errors on failure status codes', async () => {
|
|
jest
|
|
.spyOn(axios, 'post')
|
|
.mockImplementationOnce(() => Promise.reject({response: {status: 404}}))
|
|
|
|
try {
|
|
await enablePages({
|
|
repositoryNwo: GITHUB_REPOSITORY,
|
|
githubToken: GITHUB_TOKEN
|
|
})
|
|
} catch (error) {
|
|
expect(error.response.status).toEqual(404)
|
|
}
|
|
})
|
|
})
|