Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Fix array responses of role functions #112

Merged
merged 2 commits into from
Nov 29, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/nine-laws-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

Update role responses to return string arrays instead of an object containing string arrays
16 changes: 8 additions & 8 deletions src/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default class Roles {
const errorRes = await response.json();
throw Errors.HandleError(errorRes.message, response.status);
}
const actions = await response.json();
return actions;
const actionsResponse: { available_actions: string[] } = await response.json();
return actionsResponse.available_actions;
} catch (error) {
throw error;
}
Expand Down Expand Up @@ -241,8 +241,8 @@ export default class Roles {
const errorRes = await response.json();
throw Errors.HandleError(errorRes.message, response.status);
}
const addedActions: string[] = await response.json();
return addedActions;
const addActionResponse: { actions: string[] } = await response.json();
ianmuchyri marked this conversation as resolved.
Show resolved Hide resolved
return addActionResponse.actions;
} catch (error) {
throw error;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ export default class Roles {
const errorRes = await response.json();
throw Errors.HandleError(errorRes.message, response.status);
}
const actions: string[] = await response.json();
const { actions }: { actions: string[] } = await response.json();
return actions;
} catch (error) {
throw error;
Expand Down Expand Up @@ -387,8 +387,8 @@ export default class Roles {
const errorRes = await response.json();
throw Errors.HandleError(errorRes.message, response.status);
}
const addedMembers: string[] = await response.json();
return addedMembers;
const addMembersResponse: { members: string[] } = await response.json();
ianmuchyri marked this conversation as resolved.
Show resolved Hide resolved
return addMembersResponse.members;
} catch (error) {
throw error;
}
Expand Down Expand Up @@ -428,7 +428,7 @@ export default class Roles {
const errorRes = await response.json();
throw Errors.HandleError(errorRes.message, response.status);
}
const members: string[] = await response.json();
const { members }: { members: string[] } = await response.json();
return members;
} catch (error) {
throw error;
Expand Down
10 changes: 5 additions & 5 deletions tests/clients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("Clients", () => {

test("List client actions should return available actions", async () => {
const availableActions = ["read", "write", "delete"];
fetchMock.mockResponseOnce(JSON.stringify(availableActions));
fetchMock.mockResponseOnce(JSON.stringify({ available_actions: availableActions }));

const response = await sdk.clients.ListClientActions(domainId, token);
expect(response).toEqual(availableActions);
Expand Down Expand Up @@ -250,7 +250,7 @@ describe("Clients", () => {

test("Add client role actions should add actions to a role and return updated actions", async () => {
const updatedActions = [...actions, "execute"];
fetchMock.mockResponseOnce(JSON.stringify(updatedActions));
fetchMock.mockResponseOnce(JSON.stringify({ actions: updatedActions }));

const response = await sdk.clients.AddClientRoleActions(
clientId,
Expand All @@ -263,7 +263,7 @@ describe("Clients", () => {
});

test("List client role actions should return actions of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ actions }));

const response = await sdk.clients.ListClientRoleActions(
clientId,
Expand Down Expand Up @@ -309,7 +309,7 @@ describe("Clients", () => {

test("Add client role members should add members to a role and return updated members", async () => {
const updatedMembers = [...members, "user3"];
fetchMock.mockResponseOnce(JSON.stringify(updatedMembers));
fetchMock.mockResponseOnce(JSON.stringify({ members: updatedMembers }));

const response = await sdk.clients.AddClientRoleMembers(
clientId,
Expand All @@ -322,7 +322,7 @@ describe("Clients", () => {
});

test("List client role members should return members of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(members));
fetchMock.mockResponseOnce(JSON.stringify({ members }));

const response = await sdk.clients.ListClientRoleMembers(
clientId,
Expand Down
10 changes: 5 additions & 5 deletions tests/domains.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe("Domains", () => {

test("ListDomainActions should return available actions", async () => {
const availableActions = ["read", "write", "delete"];
fetchMock.mockResponseOnce(JSON.stringify(availableActions));
fetchMock.mockResponseOnce(JSON.stringify({ available_actions: availableActions }));

const response = await sdk.domains.ListDomainActions(token);
expect(response).toEqual(availableActions);
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("Domains", () => {

test("AddDomainRoleActions should add actions to a role and return updated actions", async () => {
const updatedActions = [...actions, "execute"];
fetchMock.mockResponseOnce(JSON.stringify(updatedActions));
fetchMock.mockResponseOnce(JSON.stringify({ actions: updatedActions }));

const response = await sdk.domains.AddDomainRoleActions(
domainId,
Expand All @@ -235,7 +235,7 @@ describe("Domains", () => {
});

test("ListDomainRoleActions should return actions of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ actions }));

const response = await sdk.domains.ListDomainRoleActions(
domainId,
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("Domains", () => {

test("AddDomainRoleMembers should add members to a role and return updated members", async () => {
const updatedMembers = [...members, "user3"];
fetchMock.mockResponseOnce(JSON.stringify(updatedMembers));
fetchMock.mockResponseOnce(JSON.stringify({ members: updatedMembers }));

const response = await sdk.domains.AddDomainRoleMembers(
domainId,
Expand All @@ -290,7 +290,7 @@ describe("Domains", () => {
});

test("ListDomainRoleMembers should return members of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(members));
fetchMock.mockResponseOnce(JSON.stringify({ members }));

const response = await sdk.domains.ListDomainRoleMembers(
domainId,
Expand Down
10 changes: 5 additions & 5 deletions tests/groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe("Groups", () => {
});

test("List group actions should return all available actions for a domain", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ available_actions: actions }));
const response = await sdk.groups.ListGroupActions(domainId, token);

expect(response).toEqual(actions);
Expand Down Expand Up @@ -328,7 +328,7 @@ describe("Groups", () => {
});

test("Add group role actions should return updated actions", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ actions }));

const response = await sdk.groups.AddGroupRoleActions(
groupId,
Expand All @@ -342,7 +342,7 @@ describe("Groups", () => {
});

test("List group role actions should return a list of actions", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ actions }));

const response = await sdk.groups.ListGroupRoleActions(
groupId,
Expand Down Expand Up @@ -389,7 +389,7 @@ describe("Groups", () => {
expect(response).toEqual(deleteRoleActionResponse);
});
test("Add group role members should return created members", async () => {
fetchMock.mockResponseOnce(JSON.stringify(members));
fetchMock.mockResponseOnce(JSON.stringify({ members }));

const response = await sdk.groups.AddGroupRoleMembers(
groupId,
Expand All @@ -403,7 +403,7 @@ describe("Groups", () => {
});

test("List group role members should return members", async () => {
fetchMock.mockResponseOnce(JSON.stringify(members));
fetchMock.mockResponseOnce(JSON.stringify({ members }));

const response = await sdk.groups.ListGroupRoleMembers(
groupId,
Expand Down
10 changes: 5 additions & 5 deletions tests/roles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe("Roles", () => {

test("List available actions should return available actions", async () => {
const availableActions = ["read", "write", "delete"];
fetchMock.mockResponseOnce(JSON.stringify(availableActions));
fetchMock.mockResponseOnce(JSON.stringify({ available_actions: availableActions }));

const response = await roles.ListAvailableActions(baseUrl, endpoint, token);
expect(response).toEqual(availableActions);
Expand Down Expand Up @@ -104,7 +104,7 @@ describe("Roles", () => {

test("Add role actions should add actions to a role and return updated actions", async () => {
const updatedActions = [...actions, "execute"];
fetchMock.mockResponseOnce(JSON.stringify(updatedActions));
fetchMock.mockResponseOnce(JSON.stringify({ actions: updatedActions }));

const response = await roles.AddRoleActions(
baseUrl,
Expand All @@ -118,7 +118,7 @@ describe("Roles", () => {
});

test("List role actions should return actions of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(actions));
fetchMock.mockResponseOnce(JSON.stringify({ actions }));

const response = await roles.ListRoleActions(
baseUrl,
Expand Down Expand Up @@ -167,7 +167,7 @@ describe("Roles", () => {

test("Add role members should add members to a role and return updated members", async () => {
const updatedMembers = [...members, "user3"];
fetchMock.mockResponseOnce(JSON.stringify(updatedMembers));
fetchMock.mockResponseOnce(JSON.stringify({ members: updatedMembers }));

const response = await roles.AddRoleMembers(
baseUrl,
Expand All @@ -181,7 +181,7 @@ describe("Roles", () => {
});

test("List role members should return members of a specific role", async () => {
fetchMock.mockResponseOnce(JSON.stringify(members));
fetchMock.mockResponseOnce(JSON.stringify({ members }));

const response = await roles.ListRoleMembers(
baseUrl,
Expand Down