Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logs: deploy command instructs user to link to a site if one is … #6867

Merged
merged 9 commits into from
Oct 18, 2024
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,
)
})
})
})
Loading