mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 18:14:51 +00:00
Before return site domain & path, create the site
This commit is contained in:
48
src/enable-pages.test.js
Normal file
48
src/enable-pages.test.js
Normal file
@@ -0,0 +1,48 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user