Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/radar/radar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@ describe('Radar', () => {
expect(fetchBody()).toEqual(
expect.objectContaining({ entry: 'test_entry' }),
);
expect(result.message).toBe('Entry already present in list');
expect(result?.message).toBe('Entry already present in list');
});

it('returns null when the entry is added successfully', async () => {
fetchOnce(undefined, { status: 204, headers: { 'content-type': '' } });

const result = await workos.radar.addListEntry({
type: 'ip_address',
action: 'block',
entry: 'test_entry',
});

expect(result).toBeNull();
});
});

Expand Down
9 changes: 7 additions & 2 deletions src/radar/radar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export class Radar {
* @example "block"
* @param options.entry - The value to add to the list. Must match the format of the list type (e.g. a valid IP address for `ip_address`, a valid email for `email`).
* @example "198.51.100.42"
* @returns {Promise<RadarListEntryAlreadyPresentResponse>}
* @returns {Promise<RadarListEntryAlreadyPresentResponse | null>}
* @throws {BadRequestException} 400
*/
async addListEntry(
options: AddListEntryOptions,
): Promise<RadarListEntryAlreadyPresentResponse> {
): Promise<RadarListEntryAlreadyPresentResponse | null> {
Comment thread
greptile-apps[bot] marked this conversation as resolved.
const { type, action, ...payload } = options;
const { data } = await this.workos.post<
RadarListEntryAlreadyPresentResponseWire,
Expand All @@ -107,6 +107,11 @@ export class Radar {
`/radar/lists/${encodeURIComponent(type)}/${encodeURIComponent(action)}`,
serializeRadarStandaloneUpdateRadarListRequest(payload),
);
if (!data) {
// Adding an entry successfully returns 204 No Content,
// so we can't deserialize the response.
return null;
}
return deserializeRadarListEntryAlreadyPresentResponse(data);
}

Expand Down
Loading