Skip to content

Commit 5d9e7bf

Browse files
committed
test(cloudflare): cover explicit lifecycle replacement intent
1 parent 1f0dd8a commit 5d9e7bf

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

‎apps/sim/tools/cloudflare/request-boundary.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,57 @@
11
import { describe, expect, it } from 'vitest'
22
import { createDnsRecordTool } from '@/tools/cloudflare/create_dns_record'
33
import { deleteDnsRecordTool } from '@/tools/cloudflare/delete_dns_record'
4+
import { updateR2BucketLifecycleTool } from '@/tools/cloudflare/update_r2_bucket_lifecycle'
45
import { updateRulesetRuleTool } from '@/tools/cloudflare/update_ruleset_rule'
56

67
describe('Cloudflare provider request boundaries', () => {
8+
it.each([undefined, null, '', ' '])(
9+
'rejects an R2 lifecycle replacement without explicit rules (%j)',
10+
(rules) => {
11+
const body = updateR2BucketLifecycleTool.request.body
12+
if (!body) throw new Error('Expected a request body')
13+
const wireInput = { apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules }
14+
expect(() => Reflect.apply(body, undefined, [wireInput])).toThrow(/rules/)
15+
}
16+
)
17+
18+
it.each([[], '[]'])('preserves an explicit R2 lifecycle clear (%j)', (rules) => {
19+
const body = updateR2BucketLifecycleTool.request.body
20+
if (!body) throw new Error('Expected a request body')
21+
expect(body({ apiKey: 'token', accountId: 'account', bucketName: 'bucket', rules })).toEqual({
22+
rules: [],
23+
})
24+
})
25+
26+
it('preserves every explicitly supplied R2 lifecycle rule', () => {
27+
const body = updateR2BucketLifecycleTool.request.body
28+
if (!body) throw new Error('Expected a request body')
29+
const rules = [
30+
{
31+
id: 'expire-logs',
32+
enabled: true,
33+
conditions: { prefix: 'logs/' },
34+
deleteObjectsTransition: { condition: { type: 'Age', maxAge: 86400 } },
35+
},
36+
{
37+
id: 'retain-archive-transition',
38+
enabled: false,
39+
conditions: { prefix: 'archive/' },
40+
storageClassTransitions: [
41+
{ condition: { type: 'Age', maxAge: 2592000 }, storageClass: 'InfrequentAccess' },
42+
],
43+
},
44+
]
45+
expect(
46+
body({
47+
apiKey: 'token',
48+
accountId: 'account',
49+
bucketName: 'bucket',
50+
rules: JSON.stringify(rules),
51+
})
52+
).toEqual({ rules })
53+
})
54+
755
it('rejects a DNS deletion identifier that would address the collection instead', () => {
856
const url = deleteDnsRecordTool.request.url
957
if (typeof url !== 'function') throw new Error('Expected a parameterized URL')

0 commit comments

Comments
 (0)