175
).not.toHaveProperty('authHintUrl');
176
});
177
178
+ /**
179
+ * The generated client declares both groups, but responses that omit one do
180
+ * occur: this repo's own docs pipeline defaults them (`docs/lib/toolkit-api.ts`).
181
+ * A missing group used to reach zod and fail validation; mapping it eagerly
182
+ * would throw a TypeError before validation instead.
183
+ */
184
+ describe('when the API omits a field group', () => {
185
+ const withDetail = (detail: unknown) =>
186
+ ({ ...rawToolkit, auth_config_details: [detail] }) as unknown as RawRetrieveResponse;
187
+
188
+ const populatedInitiation = {
189
+ required: [
190
+ {
191
+ name: 'api_key',
192
+ displayName: 'API Key',
193
+ description: 'Your API key',
194
+ type: 'string',
195
+ required: true,
196
+ is_secret: true,
197
+ },
198
+ ],
199
+ optional: [],
200
+ };
201
+
202
+ it('returns empty lists for a missing auth_config_creation and keeps the other group', () => {
203
+ const detail = {
204
+ name: 'API Key',
205
+ mode: 'API_KEY',
206
+ fields: { connected_account_initiation: populatedInitiation },
207
+ };
208
+
209
+ const fields = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
210
+ .fields;
211
+
212
+ expect(fields?.authConfigCreation).toEqual({ required: [], optional: [] });
213
+ expect(fields?.connectedAccountInitiation.required[0]).toEqual({
214
+ name: 'api_key',
215
+ displayName: 'API Key',
216
+ description: 'Your API key',
217
+ type: 'string',
218
+ required: true,
219
+ isSecret: true,
220
+ });
221
+ });
222
+
223
+ it('returns empty lists for a missing connected_account_initiation and keeps the other group', () => {
224
+ const detail = {
225
+ name: 'API Key',
226
+ mode: 'API_KEY',
227
+ fields: { auth_config_creation: populatedInitiation },
228
+ };
229
+
230
+ const fields = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
231
+ .fields;
232
+
233
+ expect(fields?.connectedAccountInitiation).toEqual({ required: [], optional: [] });
234
+ expect(fields?.authConfigCreation.required).toHaveLength(1);
235
+ });
236
+
237
+ it('fills in a list the group itself is missing', () => {
238
+ const detail = {
239
+ name: 'API Key',
240
+ mode: 'API_KEY',
241
+ fields: {
242
+ auth_config_creation: { required: [], optional: [] },
243
+ connected_account_initiation: { optional: populatedInitiation.required },
244
+ },
245
+ };
246
+
247
+ const group = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
248
+ .fields.connectedAccountInitiation;
249
+
250
+ expect(group?.required).toEqual([]);
251
+ expect(group?.optional).toHaveLength(1);
252
+ });
253
+
254
+ it('treats a null group like a missing one', () => {
255
+ const detail = {
256
+ name: 'API Key',
257
+ mode: 'API_KEY',
258
+ fields: { auth_config_creation: null, connected_account_initiation: populatedInitiation },
259
+ };
260
+
261
+ expect(() => transformToolkitRetrieveResponse(withDetail(detail))).not.toThrow();
262
+ expect(
263
+ transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0].fields
264
+ .authConfigCreation
265
+ ).toEqual({ required: [], optional: [] });
266
+ });
267
+ });
268
+
269
it('lets a caller fallback survive spreading a field with no default', () => {
270
const field = initiationRequired(rawToolkitWithoutOptionalKeys);
271