Skip to content

Commit

Permalink
fix: logs: deploy command instructs user to link to a site if one is … (
Browse files Browse the repository at this point in the history
#6867)

* fix: logs: deploy command instructs user to link to a site if one is not linked

Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>

* fix: logs: deploy command instructs user to link to a site if one is not linked

* fix: logs:deploy command instructs user to link to a site if one is not linked

Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>

* fix: logs: deploy command instructs user to link to a site if one is not linked

Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>

* fix: logs: deploy command instructs user to link to a site if one is not linked

Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>

---------

Co-authored-by: Dylan Spyer <dylanspyer@gmail.com>
Co-authored-by: Daniel Lew <51924260+DanielSLew@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 18, 2024
1 parent 552e8e1 commit 98763f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/commands/logs/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export const logsBuild = async (options: OptionValues, command: BaseCommand) =>
const { id: siteId } = site
const userId = command.netlify.globalConfig.get('userId')

if (!siteId) {
log('You must link a site before attempting to view deploy logs')
return
}

const deploys = await client.listSiteDeploys({ siteId, state: 'building' })

if (deploys.length === 0) {
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/commands/logs/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { createLogsBuildCommand } from '../../../../src/commands/logs/index.js'
import { getWebSocket } from '../../../../src/utils/websockets/index.js'
import { startMockApi } from '../../utils/mock-api-vitest.js'
import { getEnvironmentVariables } from '../../utils/mock-api.js'
import { callCli } from '../../utils/call-cli.js'
import { getCLIOptions, withMockApi } from '../../utils/mock-api.js'
import { withSiteBuilder } from '../../utils/site-builder.ts'
import { join } from 'path'

vi.mock('../../../../src/utils/websockets/index.js', () => ({
getWebSocket: vi.fn(),
Expand Down Expand Up @@ -47,12 +51,14 @@ const routes = [

describe('logs:deploy command', () => {
let program: BaseCommand
const originalEnv = { ...process.env }

afterEach(() => {
vi.clearAllMocks()
})

beforeEach(() => {
process.env = { ...originalEnv }
program = new BaseCommand('netlify')

createLogsBuildCommand(program)
Expand Down Expand Up @@ -107,4 +113,21 @@ describe('logs:deploy command', () => {
expect(body.site_id).toEqual('site_id')
expect(body.access_token).toEqual(env.NETLIFY_AUTH_TOKEN)
})

test('should instruct user to link a site if one is not linked', async (t) => {
await withSiteBuilder(t, async (builder) => {
const projectPath = join('projects', 'project1')
await builder.withNetlifyToml({ config: {}, pathPrefix: projectPath }).build()

await withMockApi(
routes,
async ({ apiUrl }) => {
const options = getCLIOptions({ builder, apiUrl, env: { NETLIFY_SITE_ID: '' } })
const stdout = await callCli(['logs:deploy'], { ...options, cwd: join(builder.directory, projectPath) })
expect(stdout).toContain('You must link a site before attempting to view deploy logs')
},
true,
)
})
})
})

0 comments on commit 98763f7

Please sign in to comment.