Skip to content

Commit

Permalink
fix: remove ambiguity between auth User and UA user (#782)
Browse files Browse the repository at this point in the history
* fix: remove ambiguity between auth User and UA user

closes #781

* fix(user): expose user resource and interfaces
  • Loading branch information
gdostie authored Dec 14, 2023
1 parent dfdf574 commit cddfb3d
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 100 deletions.
67 changes: 67 additions & 0 deletions src/resources/UsageAnalytics/Read/UAUsers/UAUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {ReadServiceHealthApi, ReadServiceHealthResponse, ReadServiceStatusResponse} from '../ReadServiceCommon.js';
import ReadServiceResource from '../ReadServiceResource.js';
import {
UAUserFilterParams,
UAUsersFiltersModel,
ListUAUsersFiltersParams,
ListUAUsersReportsParams,
UAUsersReportsModel,
UAUserModel,
} from './UAUsersInterfaces.js';

export default class UAUsers extends ReadServiceResource implements ReadServiceHealthApi {
static baseUrl = '/rest/ua/v15/users';

/**
* Get the data level filters that apply to a user.
*
* @param userId The unique identifier of a user.
*/
listUserFilters(userId: string, params?: ListUAUsersFiltersParams) {
return this.api.get<UAUsersFiltersModel>(this.buildPathWithOrg(`${UAUsers.baseUrl}/${userId}/filters`, params));
}

/**
* Set the filters that will be applied to a user query.
*
* @param userId The unique identifier of a user.
*/
updateUserFilters(userId: string, filters: UAUserFilterParams[]) {
return this.api.put<void>(this.buildPathWithOrg(`${UAUsers.baseUrl}/${userId}/filters`), filters);
}

/**
* Get the reports that a user can access.
*
* @param userId The unique identifier of a user.
*/
listUsersReports(userId: string, params?: ListUAUsersReportsParams) {
return this.api.get<UAUsersReportsModel>(this.buildPathWithOrg(`${UAUsers.baseUrl}/${userId}/reports`, params));
}

/**
* Set which reports a user can access.
*
* @param userId The unique identifier of a user.
*/
updateUsersReports(userId: string, reportsIDs: string[]) {
return this.api.put<void>(this.buildPathWithOrg(`${UAUsers.baseUrl}/${userId}/reports`), reportsIDs);
}

/**
* Get a user.
*
* @param userId The unique identifier of a user.
*/
getUser(userId: string) {
return this.api.get<UAUserModel>(this.buildPathWithOrg(`${UAUsers.baseUrl}/${userId}`));
}

checkHealth() {
return this.api.get<ReadServiceHealthResponse>(`${UAUsers.baseUrl}/monitoring/health`);
}

checkStatus() {
return this.api.get<ReadServiceStatusResponse>(`${UAUsers.baseUrl}/status`);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {OrganizationParamParts} from '../CommonParamParts.js';

export interface UsersFilterModel {
export interface UAUsersFilterModel {
/**
* The filter id
*/
Expand All @@ -23,14 +23,14 @@ export interface UsersFilterModel {
value: string;
}

export interface UsersFiltersModel {
export interface UAUsersFiltersModel {
/**
* The filters that are applied to the user
*/
filters: UsersFilterModel[];
filters: UAUsersFilterModel[];
}

export interface UsersReportModel {
export interface UAUsersReportModel {
/**
* The report id
*/
Expand Down Expand Up @@ -61,14 +61,14 @@ export interface UsersReportModel {
filters: string[];
}

export interface UsersReportsModel {
export interface UAUsersReportsModel {
/**
* The reports the user can view
*/
reports: UsersReportModel[];
reports: UAUsersReportModel[];
}

export interface UserModel {
export interface UAUserModel {
/**
* The user id
*/
Expand All @@ -87,14 +87,14 @@ export interface UserModel {
reports: string[];
}

export interface ListUsersFiltersParams extends OrganizationParamParts {
export interface ListUAUsersFiltersParams extends OrganizationParamParts {
/**
* Whether to include th values inherited from a user's groups in the response
*/
includeGroups?: boolean;
}

export interface FilterParams {
export interface UAUserFilterParams {
/**
* The id or value of the filter.
*/
Expand All @@ -105,7 +105,7 @@ export interface FilterParams {
id: boolean;
}

export interface ListUsersReportsParams extends OrganizationParamParts {
export interface ListUAUsersReportsParams extends OrganizationParamParts {
/**
* Whether to include the detailed configuration of the report in the response.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/resources/UsageAnalytics/Read/UAUsers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './UAUsers.js';
export * from './UAUsersInterfaces.js';
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
import API from '../../../../../APICore.js';
import Users from '../Users.js';
import {FilterParams, ListUsersReportsParams} from '../UsersInterfaces.js';
import UAUsers from '../UAUsers.js';
import {UAUserFilterParams, ListUAUsersReportsParams} from '../UAUsersInterfaces.js';

jest.mock('../../../../../APICore.js');

const APIMock: jest.Mock<API> = API as any;

describe('Statistics', () => {
let users: Users;
let users: UAUsers;
const api = new APIMock() as jest.Mocked<API>;
const serverlessApi = new APIMock() as jest.Mocked<API>;

beforeEach(() => {
jest.clearAllMocks();
users = new Users(api, serverlessApi);
users = new UAUsers(api, serverlessApi);
});

describe('ListUserFilters', () => {
it('should make a GET call to the user filters url', () => {
const userId = 'CouliliZazou';
users.listUserFilters('CouliliZazou');
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Users.baseUrl}/${userId}/filters`);
expect(api.get).toHaveBeenCalledWith(`${UAUsers.baseUrl}/${userId}/filters`);
});
});

describe('UpdateUserFilters', () => {
it('should make a PUT call to the specific user filters url', () => {
const userId = 'Jida';
const filters: FilterParams[] = [
const filters: UAUserFilterParams[] = [
{
value: 'tuna-durgod',
id: true,
},
];
users.updateUserFilters(userId, filters);
expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${Users.baseUrl}/${userId}/filters`, filters);
expect(api.put).toHaveBeenCalledWith(`${UAUsers.baseUrl}/${userId}/filters`, filters);
});
});

describe('ListUsersReports', () => {
it('should make a GET call to the specific Users url', () => {
const userId = 'Jida';
const params: ListUsersReportsParams = {
const params: ListUAUsersReportsParams = {
includeConfig: false,
includeGroups: false,
};
users.listUsersReports(userId, params);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${Users.baseUrl}/${userId}/reports?includeConfig=false&includeGroups=false`,
`${UAUsers.baseUrl}/${userId}/reports?includeConfig=false&includeGroups=false`,
);
});
});
Expand All @@ -62,7 +62,7 @@ describe('Statistics', () => {

users.updateUsersReports(userId, reportsIds);
expect(api.put).toHaveBeenCalledTimes(1);
expect(api.put).toHaveBeenCalledWith(`${Users.baseUrl}/${userId}/reports`, reportsIds);
expect(api.put).toHaveBeenCalledWith(`${UAUsers.baseUrl}/${userId}/reports`, reportsIds);
});
});

Expand All @@ -71,23 +71,23 @@ describe('Statistics', () => {
const userId = 'Jida';
users.getUser(userId);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Users.baseUrl}/${userId}`);
expect(api.get).toHaveBeenCalledWith(`${UAUsers.baseUrl}/${userId}`);
});
});

describe('checkHealth', () => {
it('should make a GET call to /v15/users/monitoring/health', () => {
users.checkHealth();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Users.baseUrl}/monitoring/health`);
expect(api.get).toHaveBeenCalledWith(`${UAUsers.baseUrl}/monitoring/health`);
});
});

describe('checkStatus', () => {
it('should make a GET call to /v15/users/status with specific options', () => {
users.checkStatus();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${Users.baseUrl}/status`);
expect(api.get).toHaveBeenCalledWith(`${UAUsers.baseUrl}/status`);
});
});
});
67 changes: 0 additions & 67 deletions src/resources/UsageAnalytics/Read/Users/Users.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/resources/UsageAnalytics/Read/Users/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/resources/UsageAnalytics/Read/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export * from './Filters/index.js';
export * from './Reports/index.js';
export * from './Snowflake/index.js';
export * from './Statistics/index.js';
export * from './Users/index.js';

export * from './UAUsers/index.js';
export * from './ReadServiceCommon.js';
export * from './ReadServiceResource.js';
3 changes: 3 additions & 0 deletions src/resources/UsageAnalytics/UsageAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Reports from './Read/Reports/Reports.js';
import Snowflake from './Read/Snowflake/Snowflake.js';
import Statistics from './Read/Statistics/Statistics.js';
import DataHealth from './Read/DataHealth/DataHealth.js';
import UAUsers from './Read/UAUsers/UAUsers.js';

export default class UsageAnalytics extends Resource {
administration: Administration;
Expand All @@ -20,6 +21,7 @@ export default class UsageAnalytics extends Resource {
reports: Reports;
snowflake: Snowflake;
statistics: Statistics;
users: UAUsers;

constructor(
protected api: API,
Expand All @@ -36,5 +38,6 @@ export default class UsageAnalytics extends Resource {
this.reports = new Reports(api, serverlessApi);
this.snowflake = new Snowflake(api, serverlessApi);
this.statistics = new Statistics(api, serverlessApi);
this.users = new UAUsers(api, serverlessApi);
}
}
6 changes: 6 additions & 0 deletions src/resources/UsageAnalytics/tests/UsageAnalytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Filters from '../Read/Filters/Filters.js';
import Reports from '../Read/Reports/Reports.js';
import Snowflake from '../Read/Snowflake/Snowflake.js';
import Statistics from '../Read/Statistics/Statistics.js';
import UAUsers from '../Read/UAUsers/UAUsers.js';
import UsageAnalytics from '../UsageAnalytics.js';

jest.mock('../../../APICore.js');
Expand Down Expand Up @@ -56,4 +57,9 @@ describe('UsageAnalytics', () => {
expect(ua.filters).toBeDefined();
expect(ua.filters).toBeInstanceOf(Filters);
});

it('registers the users resource', () => {
expect(ua.users).toBeDefined();
expect(ua.users).toBeInstanceOf(UAUsers);
});
});
Loading

0 comments on commit cddfb3d

Please sign in to comment.