Skip to content

Commit

Permalink
test: add deploy test for --auth and blobs uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Sep 25, 2024
1 parent 6a97ea2 commit 4fcd76d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/integration/commands/deploy/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import execa from 'execa'
import fetch from 'node-fetch'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'

import { getToken } from '../../../../src/utils/command-helpers.ts'
import { callCli } from '../../utils/call-cli.js'
import { createLiveTestSite, generateSiteName } from '../../utils/create-live-test-site.js'
import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'
Expand Down Expand Up @@ -953,6 +954,71 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
})
})

test.only('should upload blobs when saved into .netlify directory and using --auth flag', async (t) => {
await withSiteBuilder(t, async (builder) => {
await builder
.withNetlifyToml({
config: {
build: { functions: 'functions', publish: 'dist' },
},
})
.withContentFile({
path: 'dist/index.html',
content: '<a href="/read-blob">get blob</a>',
})
.withContentFile({
path: '.netlify/blobs/deploy/hello',
content: 'hello from the blob',
})
.withPackageJson({
packageJson: {
dependencies: {
'@netlify/blobs': '^6.3.0',
'@netlify/functions': '^2.4.0',
},
},
})
.withContentFile({
path: 'functions/read-blob.ts',
content: `
import { getDeployStore } from "@netlify/blobs"
import { Config } from "@netlify/functions"
export default async () => {
const store = getDeployStore()
const blob = await store.get('hello')
return new Response(blob)
}
export const config: Config = {
path: "/read-blob"
}
`,
})
.build()

const [authToken] = await getToken('')

if (!authToken) {
throw new Error('Failed to get current auth token')
}

await execa.command('npm install', { cwd: builder.directory })
const { deploy_url: deployUrl } = await callCli(
['deploy', '--json', '--auth', authToken],
{
cwd: builder.directory,
env: { NETLIFY_SITE_ID: context.siteId, NETLIFY_AUTH_TOKEN: '' },
},
true,
)

const response = await fetch(`${deployUrl}/read-blob`).then((res) => res.text())
t.expect(response).toEqual('hello from the blob')
})
})

setupFixtureTests('next-app-without-config', () => {
test<FixtureTestContext>(
'should run deploy with --build without any netlify specific configuration',
Expand Down

0 comments on commit 4fcd76d

Please sign in to comment.