Files
floci-ui/packages/api/src/services/lightsailDeployment.test.ts
T
Zakaria 51a0a60a73
CI / checks (pull_request) Successful in 25m28s
test(api): stop tests leaking module mocks and env into later files
CI failed on a different set of tests each run because bun runs every test
file in one process and the file order differs between machines:

- the secretsmanager route test replaced the whole ../aws module, so files
  loaded after it lost awsClients, lambda and defaultAccountId (API Gateway,
  SES)
- the Lightsail tests restored FLOCI_ENDPOINT by assigning undefined, which
  stores the string "undefined" (runtime diagnostics)
- the auth tests used full-strength argon2 for ~30 sign-ins and timed out on
  slower runners; the OIDC cleanup test cached a discovery document without
  userinfo_endpoint for the shared issuer

Checked with 20 runs under bun test --randomize.
2026-10-24 11:30:46 -04:00

45 lines
2.4 KiB
TypeScript

import {afterEach, describe, expect, mock, test} from 'bun:test'
import {deployLightsailNodeApplication, deployLightsailStaticFiles} from './lightsailDeployment'
const originalEndpoint = process.env.FLOCI_ENDPOINT
const originalFetch = globalThis.fetch
afterEach(() => {
// Assigning undefined would store the string "undefined" for every later test file.
if (originalEndpoint === undefined) delete process.env.FLOCI_ENDPOINT
else process.env.FLOCI_ENDPOINT = originalEndpoint
globalThis.fetch = originalFetch
mock.restore()
})
describe('deployLightsailNodeApplication', () => {
test('forwards package uploads and preserves core deployment diagnostics', async () => {
process.env.FLOCI_ENDPOINT = 'http://core.test:4566'
const fetch = mock(() => Promise.resolve(new Response(JSON.stringify({status: 'deployed', files: 2, port: 3000, releaseId: 'release'}), {headers: {'content-type': 'application/json'}})))
globalThis.fetch = fetch as unknown as typeof globalThis.fetch
const form = new FormData()
form.append('files', new File(['{}'], 'package.json'))
form.append('port', '3000')
await expect(deployLightsailNodeApplication('node app', form)).resolves.toEqual({status: 'deployed', files: 2, port: 3000, releaseId: 'release'})
expect(fetch).toHaveBeenCalledWith('http://core.test:4566/_floci/diagnostics/lightsail/instances/node%20app/node-application', expect.objectContaining({
method: 'POST', body: form, redirect: 'error',
}))
})
})
describe('deployLightsailStaticFiles', () => {
test('forwards multipart files only to the diagnostics deployment endpoint', async () => {
process.env.FLOCI_ENDPOINT = 'http://core.test:4566'
const fetch = mock(() => Promise.resolve(new Response(JSON.stringify({status: 'deployed', files: 1}), {headers: {'content-type': 'application/json'}})))
globalThis.fetch = fetch as unknown as typeof globalThis.fetch
const form = new FormData()
form.append('files', new File(['<h1>ok</h1>'], 'site/index.html'))
await expect(deployLightsailStaticFiles('web site', form)).resolves.toEqual({status: 'deployed', files: 1})
expect(fetch).toHaveBeenCalledWith('http://core.test:4566/_floci/diagnostics/lightsail/instances/web%20site/static-files', expect.objectContaining({
method: 'POST', body: form, redirect: 'error',
}))
})
})