Skip to content

Commit 8799a1b

Browse files
committed
repair some more tests
1 parent 441b968 commit 8799a1b

File tree

4 files changed

+99
-106
lines changed

4 files changed

+99
-106
lines changed

tests/pulumi.index.test.ts

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/stacks.main.index.test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import * as pulumi from '@pulumi/pulumi'
2+
3+
import { MyMocks, promiseOf } from './utils'
4+
import * as resources from '../stacks/main/resources'
5+
6+
vi.mock('../stacks/main/resources')
7+
8+
describe('stacks/main/index.ts', () => {
9+
let envOrig: string
10+
let mocks: MyMocks
11+
let infra: typeof import('../stacks/main')
12+
13+
beforeEach(async () => {
14+
vi.resetModules()
15+
envOrig = JSON.stringify(process.env)
16+
mocks = new MyMocks()
17+
pulumi.runtime.setMocks(mocks)
18+
})
19+
20+
afterEach(() => {
21+
process.env = JSON.parse(envOrig)
22+
})
23+
24+
it('Without FQDN', async () => {
25+
;(resources.buildRouter as any).mockImplementation(() => {
26+
return 'mock'
27+
})
28+
;(resources.buildCDN as any).mockImplementation(() => {
29+
return {
30+
domainName: 'example.com',
31+
}
32+
})
33+
// @ts-ignore
34+
pulumi.Config = vi.fn(() => {
35+
return {
36+
get: vi.fn((x) => {
37+
if (x === 'serverHeaders') {
38+
return '{"mock": "mock"}'
39+
}
40+
return ''
41+
})
42+
}
43+
});
44+
45+
infra = await import('../stacks/main')
46+
47+
expect(resources.getLambdaRole).toHaveBeenCalledTimes(1)
48+
expect(resources.validateCertificate).toHaveBeenCalledTimes(0)
49+
expect(resources.buildStatic).toHaveBeenCalledTimes(1)
50+
expect(resources.buildCDN).toHaveBeenCalledTimes(1)
51+
expect(resources.createAliasRecord).toHaveBeenCalledTimes(0)
52+
expect(resources.buildInvalidator).toHaveBeenCalledTimes(1)
53+
54+
const allowedOrigin = await promiseOf(infra.allowedOrigins[0] as pulumi.Output<string>)
55+
const appUrl = await promiseOf(infra.appUrl as pulumi.Output<string>)
56+
expect(allowedOrigin).toMatch('https://example.com')
57+
expect(appUrl).toMatch('https://example.com')
58+
})
59+
60+
it('With FQDN', async () => {
61+
const fqdn = 'mock.application.net'
62+
;(resources.buildRouter as any).mockImplementation(() => {
63+
return 'mock'
64+
})
65+
;(resources.buildCDN as any).mockImplementation(() => {
66+
return {
67+
domainName: 'example.com',
68+
}
69+
})
70+
// @ts-ignore
71+
pulumi.Config = vi.fn(() => {
72+
return {
73+
get: vi.fn((x) => {
74+
if (x === 'serverHeaders') {
75+
return '{"mock": "mock"}'
76+
} else if (x === 'FQDN') {
77+
return fqdn
78+
}
79+
return ''
80+
})
81+
}
82+
});
83+
84+
infra = await import('../stacks/main')
85+
86+
expect(resources.validateCertificate).toHaveBeenCalledTimes(1)
87+
expect(resources.createAliasRecord).toHaveBeenCalledTimes(1)
88+
89+
const distOrigin = await promiseOf(infra.allowedOrigins[0] as pulumi.Output<string>)
90+
const fqdnOrigin = infra.allowedOrigins[1]
91+
92+
expect(distOrigin).toMatch('https://example.com')
93+
expect(fqdnOrigin).toMatch(`https://${fqdn}`)
94+
expect(infra.appUrl).toMatch(`https://${fqdn}`)
95+
})
96+
})
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import * as path from 'path'
33

44
import { getTempDir } from './utils'
55

6-
describe('pulumi/utils.ts', () => {
6+
describe('stacks/utils.ts', () => {
77
let envOrig: string
8-
let utils: typeof import('../pulumi/utils')
8+
let utils: typeof import('../stacks/utils')
99

1010
beforeEach(async () => {
1111
vi.resetModules()
1212
envOrig = JSON.stringify(process.env)
13-
utils = await import('../pulumi/utils')
13+
utils = await import('../stacks/utils')
1414
})
1515

1616
afterEach(() => {

0 commit comments

Comments
 (0)