diff --git a/__tests__/directory/v3/index.test.ts b/__tests__/directory/v3/index.test.ts index 23ba9b1..1b282d6 100644 --- a/__tests__/directory/v3/index.test.ts +++ b/__tests__/directory/v3/index.test.ts @@ -462,6 +462,7 @@ describe("DirectoryV3", () => { ); expect(result).toEqual({ check: true, + trace: [], }); mockCheck.mockReset(); @@ -504,9 +505,12 @@ describe("DirectoryV3", () => { const result = await directory.object(params); expect(result).toEqual({ + relations: [], result: { id: "123", type: "user", + displayName: "", + etag: "", }, }); @@ -565,7 +569,7 @@ describe("DirectoryV3", () => { ); const result = await directory.objects(params); - expect(result).toEqual({}); + expect(result).toEqual({ results: [] }); mockGetObjects.mockReset(); }); @@ -598,7 +602,7 @@ describe("DirectoryV3", () => { ); const result = await directory.objects(params); - expect(result).toEqual({}); + expect(result).toEqual({ results: [] }); mockGetObjects.mockReset(); }); @@ -631,7 +635,7 @@ describe("DirectoryV3", () => { ); const result = await directory.objects(params); - expect(result).toEqual({}); + expect(result).toEqual({ results: [] }); mockGetObjects.mockReset(); }); @@ -665,7 +669,7 @@ describe("DirectoryV3", () => { ); const result = await directory.objects(params); - expect(result).toEqual({}); + expect(result).toEqual({ results: [] }); mockGetObjects.mockReset(); }); @@ -815,7 +819,7 @@ describe("DirectoryV3", () => { const result = await directory.objectMany(params); expect(result).toEqual({ - results: [{ type: "user", id: "123" }], + results: [{ type: "user", id: "123", displayName: "", etag: "" }], }); mockGetObjectMany.mockReset(); @@ -866,6 +870,7 @@ describe("DirectoryV3", () => { ); expect(result).toEqual({ results: [{ objectId: "1234", objectType: "user" }], + trace: [], }); mockGetGraph.mockReset(); @@ -950,12 +955,15 @@ describe("DirectoryV3", () => { const result = await directory.relation(params); expect(result).toEqual({ + objects: {}, result: { + etag: "", subjectType: "user", subjectId: "123", objectType: "identity", objectId: "identity", relation: "identifier", + subjectRelation: "", }, }); @@ -1009,7 +1017,7 @@ describe("DirectoryV3", () => { ); const result = await directory.relations(params); - expect(result).toEqual({}); + expect(result).toEqual({ objects: {}, results: [] }); mockGetRelations.mockReset(); }); diff --git a/__tests__/directory/v3/serializeResponse.test.ts b/__tests__/directory/v3/serializeResponse.test.ts index eabb5a1..9323060 100644 --- a/__tests__/directory/v3/serializeResponse.test.ts +++ b/__tests__/directory/v3/serializeResponse.test.ts @@ -43,7 +43,7 @@ describe("serializeResponse() serializeResponse method", () => { type: "user", id: "123", displayName: "", - etag: "", + etag: "1234", }, relations: [], }; @@ -51,9 +51,12 @@ describe("serializeResponse() serializeResponse method", () => { const result = serializeResponse(mockResponse); expect(result).toEqual({ + relations: [], result: { id: "123", type: "user", + displayName: "", + etag: "1234", }, }); }); diff --git a/__tests__/integration/index.test.ts b/__tests__/integration/index.test.ts index cabfb17..8156287 100644 --- a/__tests__/integration/index.test.ts +++ b/__tests__/integration/index.test.ts @@ -71,6 +71,7 @@ describe("Integration", () => { expect(res.status).toBe(200); expect(res.body).toEqual({ check: true, + trace: [], }); }); @@ -258,6 +259,7 @@ describe("Integration", () => { expect(getObjectRes.status).toBe(200); expect(getObjectRes.body).toEqual({ + relations: [], result: expect.objectContaining({ id: "object-1", type: "user", @@ -291,6 +293,7 @@ describe("Integration", () => { expect(getEditedObjectRes.status).toBe(200); expect(getEditedObjectRes.body).toEqual({ + relations: [], result: expect.objectContaining({ id: "object-1", type: "user", @@ -601,8 +604,8 @@ describe("Integration", () => { {}, {}, { - object: { recv: "2", set: "2" }, - relation: { recv: "1", set: "1" }, + object: { recv: "2", set: "2", delete: "0", error: "0" }, + relation: { recv: "1", set: "1", delete: "0", error: "0" }, }, ]); }); @@ -686,6 +689,7 @@ describe("Integration", () => { object: { type: "identity", id: "CiRmZDA2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs", + displayName: "", properties: { kind: "IDENTITY_KIND_PID", provider: "local", @@ -700,6 +704,7 @@ describe("Integration", () => { object: { type: "identity", id: "CiRmZDE2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs", + displayName: "", properties: { kind: "IDENTITY_KIND_PID", provider: "local", @@ -714,6 +719,7 @@ describe("Integration", () => { object: { type: "identity", id: "CiRmZDI2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs", + displayName: "", properties: { kind: "IDENTITY_KIND_PID", provider: "local", @@ -728,6 +734,7 @@ describe("Integration", () => { object: { type: "identity", id: "CiRmZDM2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs", + displayName: "", properties: { kind: "IDENTITY_KIND_PID", provider: "local", @@ -742,6 +749,7 @@ describe("Integration", () => { object: { type: "identity", id: "CiRmZDQ2MTRkMy1jMzlhLTQ3ODEtYjdiZC04Yjk2ZjVhNTEwMGQSBWxvY2Fs", + displayName: "", properties: { kind: "IDENTITY_KIND_PID", provider: "local", @@ -756,6 +764,7 @@ describe("Integration", () => { object: { type: "identity", id: "beth@the-smiths.com", + displayName: "", properties: { kind: "IDENTITY_KIND_EMAIL", provider: "local", @@ -770,6 +779,7 @@ describe("Integration", () => { object: { type: "identity", id: "jerry@the-smiths.com", + displayName: "", properties: { kind: "IDENTITY_KIND_EMAIL", provider: "local", @@ -784,6 +794,7 @@ describe("Integration", () => { object: { type: "identity", id: "morty@the-citadel.com", + displayName: "", properties: { kind: "IDENTITY_KIND_EMAIL", provider: "local", @@ -798,6 +809,7 @@ describe("Integration", () => { object: { type: "identity", id: "rick@the-citadel.com", + displayName: "", properties: { verified: true, kind: "IDENTITY_KIND_EMAIL", @@ -812,6 +824,7 @@ describe("Integration", () => { object: { type: "identity", id: "summer@the-smiths.com", + displayName: "", properties: { kind: "IDENTITY_KIND_EMAIL", provider: "local", @@ -1229,6 +1242,7 @@ types: objectType: "group", }), ).toEqual({ + objects: {}, result: expect.objectContaining({ subjectId: "test-user", subjectType: "user", @@ -1273,6 +1287,7 @@ types: }, }), ).toEqual({ + objects: {}, page: { nextToken: "" }, results: [ expect.objectContaining({ @@ -1373,6 +1388,7 @@ types: it("returns [] when there are no objects", async () => { expect(await directoryClient.objects({ objectType: "user" })).toEqual({ page: { nextToken: "" }, + results: [], }); }); diff --git a/lib/directory/v3/index.ts b/lib/directory/v3/index.ts index d042170..7e4a20e 100644 --- a/lib/directory/v3/index.ts +++ b/lib/directory/v3/index.ts @@ -308,17 +308,12 @@ export class DirectoryV3 { params.page.size ||= 100; } - const response = serializeResponse( - await this.ReaderClient.getObject( - create(GetObjectRequestSchema, params), - options, - ), + const response = await this.ReaderClient.getObject( + create(GetObjectRequestSchema, params), + options, ); - if (response.page && response.page.nextToken === undefined) { - response.page.nextToken = ""; - } - return response; + return serializeResponse(response); } catch (error) { throw handleError(error, "object"); } @@ -331,16 +326,11 @@ export class DirectoryV3 { if (params.page) { params.page.size ||= 100; } - const response = serializeResponse( - await this.ReaderClient.getObjects( - create(GetObjectsRequestSchema, params), - options, - ), + const response = await this.ReaderClient.getObjects( + create(GetObjectsRequestSchema, params), + options, ); - if (response.page && response.page.nextToken === undefined) { - response.page.nextToken = ""; - } - return response; + return serializeResponse(response); } catch (error) { throw handleError(error, "objects"); } @@ -457,15 +447,8 @@ export class DirectoryV3 { params.page.size ||= 100; } - const response = serializeResponse( - await this.ReaderClient.getRelations(params, options), - ); - - if (response.page && response.page.nextToken === undefined) { - response.page.nextToken = ""; - } - - return response; + const response = await this.ReaderClient.getRelations(params, options); + return serializeResponse(response); } catch (error) { throw handleError(error, "relations"); } diff --git a/lib/directory/v3/serializer.ts b/lib/directory/v3/serializer.ts index b4c2f2d..e6c08ad 100644 --- a/lib/directory/v3/serializer.ts +++ b/lib/directory/v3/serializer.ts @@ -42,5 +42,5 @@ export function serializeResponse( `schema not registered for type: [${response.$typeName}]`, ); } - return toJson(schema, response) as unknown as T; + return toJson(schema, response, { alwaysEmitImplicit: true }) as unknown as T; }