Skip to content

Commit db847e8

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(oci-notifications): accept live topic creation responses
1 parent e263e8b commit db847e8

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

apps/sim/lib/internal/oci-notifications/operations.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,48 @@ describe('OCI Notifications operation contracts', () => {
7777
prepareDiscoveredEndpoint.mockReset().mockResolvedValue(data)
7878
})
7979

80+
it.each([200, 201])(
81+
'accepts CreateTopic status %i with an absent SMS identifier',
82+
async (status) => {
83+
request.mockResolvedValue(response({ ...topic, shortTopicId: null }, status))
84+
const output = await run('create_topic', { compartmentId: 'compartment', name: 'Operations' })
85+
expect(output).toMatchObject({ status, requestId: 'oracle-request', topic })
86+
expect(output.topic?.shortTopicId).toBeUndefined()
87+
expect(request).toHaveBeenCalledTimes(1)
88+
}
89+
)
90+
91+
it.each([undefined, null, 'sms-code'])(
92+
'projects optional topic identifiers: %s',
93+
async (shortTopicId) => {
94+
request.mockResolvedValue(response([{ ...topic, shortTopicId }]))
95+
const output = await run('list_topics', { compartmentId: 'compartment' })
96+
expect(output.topics?.[0].shortTopicId).toBe(shortTopicId ?? undefined)
97+
}
98+
)
99+
100+
it('retains authenticated discovery with null SMS identifiers', async () => {
101+
const discovery = response({ ...topic, shortTopicId: null })
102+
request.mockResolvedValueOnce(discovery).mockResolvedValueOnce(response([subscription]))
103+
expect(
104+
(await run('list_subscriptions', { compartmentId: 'compartment' })).subscriptions
105+
).toEqual([subscription])
106+
expect(prepareDiscoveredEndpoint).toHaveBeenCalledWith(expect.anything(), discovery)
107+
})
108+
109+
it('does not broaden other statuses or malformed topic identifiers', async () => {
110+
request.mockResolvedValue(response(topic, 201))
111+
await expect(run('get_topic')).rejects.toThrow('unexpected response status')
112+
request.mockResolvedValue(response(topic, 202))
113+
await expect(
114+
run('create_topic', { compartmentId: 'compartment', name: 'Operations' })
115+
).rejects.toThrow('unexpected response status')
116+
request.mockResolvedValue(response([{ ...topic, shortTopicId: 42 }]))
117+
await expect(run('list_topics', { compartmentId: 'compartment' })).rejects.toThrow(
118+
'invalid response'
119+
)
120+
})
121+
80122
it('lists one bare topic array and preserves opaque pagination without discovery', async () => {
81123
request.mockResolvedValue(response([topic], 200, { 'opc-next-page': 'next+/=' }))
82124
expect(

apps/sim/lib/internal/oci-notifications/operations.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ export async function executeOciNotificationsOperation(
228228
try {
229229
const response = await prepared.client.request(request)
230230
signal?.throwIfAborted()
231-
if (response.status !== expectedStatus) {
231+
/** Oracle documents 200, while its live CreateTopic endpoint also returns 201. */
232+
const createdTopic =
233+
input.operation === 'oci_notifications_create_topic' && response.status === 201
234+
if (response.status !== expectedStatus && !createdTopic) {
232235
throw new OciNotificationsOperationError(
233236
'OCI Notifications returned an unexpected response status',
234237
502,

apps/sim/lib/internal/oci-notifications/schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ export const ociNotificationsTopicSchema = z.object({
150150
apiEndpoint: z.string(),
151151
description: z.string().optional(),
152152
etag: z.string().optional(),
153-
shortTopicId: z.string().optional(),
153+
shortTopicId: z
154+
.string()
155+
.nullish()
156+
.transform((value) => value ?? undefined),
154157
locks: z.array(ociNotificationsLockSchema).optional(),
155158
...tags,
156159
systemTags: z.record(z.string(), z.record(z.string(), z.string())).optional(),

0 commit comments

Comments
 (0)