Skip to content

Commit

Permalink
+tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Oct 7, 2024
1 parent cd2d364 commit 1d22502
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 123 deletions.
10 changes: 10 additions & 0 deletions docs/additional_info/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Unreleased

* Added `role_id` attribute to the user group object. For example:

```js
const user_group = await lokaliseApi.userGroups().get(groupId, {
team_id: teamId,
});

user_group.role_id; // => 5
```

* Migrate from eslint to biome
* Use tsup for compilation

Expand Down
25 changes: 11 additions & 14 deletions src/collections/permission_templates.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import {BaseCollection} from "./base_collection.js";
import {PermissionTemplate} from "../models/permission_template.js";
import type {TeamOnly} from "../types/index.js";
import type {PaginatedResult} from "../interfaces/index.js";

import type { PaginatedResult } from "../interfaces/index.js";
import { PermissionTemplate } from "../models/permission_template.js";
import type { TeamOnly } from "../types/index.js";
import { BaseCollection } from "./base_collection.js";

export class PermissionTemplates extends BaseCollection {
protected static prefixURI = "teams/{!:team_id}/roles";
protected static elementClass = PermissionTemplate;
protected static rootElementName = "roles"
protected static prefixURI = "teams/{!:team_id}/roles";
protected static elementClass = PermissionTemplate;
protected static rootElementName = "roles";

list(
request_params: TeamOnly,
): Promise<PaginatedResult<PermissionTemplate>> {
return this.doList(request_params);
}
}
list(request_params: TeamOnly): Promise<PaginatedResult<PermissionTemplate>> {
return this.doList(request_params);
}
}
6 changes: 3 additions & 3 deletions src/interfaces/user_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ export interface UserGroup {
group_id: number;
name: string;
permissions: {
is_admin: boolean; //deprecated
is_reviewer: boolean; //deprecated
is_admin: boolean; // deprecated
is_reviewer: boolean; // deprecated
admin_rights: string[];
languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
role_id: number;
};
created_at: string;
created_at_timestamp: number;
team_id: number;
projects: string[] | number[];
members: number[] | string[];
role_id: number | null;
}
2 changes: 1 addition & 1 deletion src/lokalise/lokalise_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Keys } from "../collections/keys.js";
import { Languages } from "../collections/languages.js";
import { Orders } from "../collections/orders.js";
import { PaymentCards } from "../collections/payment_cards.js";
import { PermissionTemplates } from "../collections/permission_templates.js";
import { Projects } from "../collections/projects.js";
import { QueuedProcesses } from "../collections/queued_processes.js";
import { Screenshots } from "../collections/screenshots.js";
Expand All @@ -22,7 +23,6 @@ import { Translations } from "../collections/translations.js";
import { UserGroups } from "../collections/user_groups.js";
import { Webhooks } from "../collections/webhooks.js";
import { BaseClient, ClientParams } from "./base_client.js";
import {PermissionTemplates} from "../collections/permission_templates.js";

export { ClientParams };

Expand Down
4 changes: 2 additions & 2 deletions src/models/contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export class Contributor extends BaseModel implements ContributorInterface {
declare fullname: string;
declare created_at: string;
declare created_at_timestamp: number;
declare is_admin: boolean; //deprecated
declare is_reviewer: boolean; //deprecated
declare is_admin: boolean; //deprecated
declare is_reviewer: boolean; //deprecated
declare languages: Array<{
lang_id: number;
lang_iso: string;
Expand Down
5 changes: 4 additions & 1 deletion src/models/permission_template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { PermissionTemplate as PermissionTemplateInterface } from "../interfaces/permission_template.js";
import { BaseModel } from "./base_model.js";

export class PermissionTemplate extends BaseModel implements PermissionTemplateInterface {
export class PermissionTemplate
extends BaseModel
implements PermissionTemplateInterface
{
declare id: number;
declare role: string;
declare permissions: string[];
Expand Down
6 changes: 3 additions & 3 deletions src/models/user_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ export class UserGroup extends BaseModel implements UserGroupInterface {
declare group_id: number;
declare name: string;
declare permissions: {
is_admin: boolean;//deprecated
is_reviewer: boolean;//deprecated
is_admin: boolean; // deprecated
is_reviewer: boolean; // deprecated
admin_rights: string[];
languages: Array<{
lang_id: number;
lang_iso: string;
lang_name: string;
is_writable: boolean;
}>;
role_id: number;
};
declare created_at: string;
declare created_at_timestamp: number;
declare team_id: number;
declare projects: string[] | number[];
declare members: number[] | string[];
declare role_id: number | null;
}
164 changes: 79 additions & 85 deletions test/fixtures/permission_templates/list.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,80 @@
{
"roles": [
{
"id": 1,
"role": "Localisation management",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"branches_merge",
"statistics",
"tasks",
"contributors",
"settings",
"manage_languages",
"download",
"upload",
"glossary_delete",
"glossary_edit",
"manage_keys",
"screenshots",
"custom_status_modify"
],
"description": "Manage project settings, contributors and tasks",
"tag": "Full access",
"tagColor": "green",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 2,
"role": "Developer",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"download",
"upload",
"manage_keys",
"screenshots"
],
"description": "Create keys, upload and download content",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 3,
"role": "Content creator",
"permissions": [
"activity",
"manage_keys",
"manage_languages",
"screenshots",
"branches_main_modify"
],
"description": "Create, translate and edit keys, manage screenshots",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 4,
"role": "Reviewer",
"permissions": [
"branches_main_modify",
"review",
"custom_status_modify"
],
"description": "Translate keys, control key statuses",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
},
{
"id": 5,
"role": "Translator",
"permissions": [
"branches_main_modify"
],
"description": "Translate keys",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
}
]
}
"roles": [
{
"id": 1,
"role": "Localisation management",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"branches_merge",
"statistics",
"tasks",
"contributors",
"settings",
"manage_languages",
"download",
"upload",
"glossary_delete",
"glossary_edit",
"manage_keys",
"screenshots",
"custom_status_modify"
],
"description": "Manage project settings, contributors and tasks",
"tag": "Full access",
"tagColor": "green",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 2,
"role": "Developer",
"permissions": [
"activity",
"branches_main_modify",
"branches_create",
"download",
"upload",
"manage_keys",
"screenshots"
],
"description": "Create keys, upload and download content",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 3,
"role": "Content creator",
"permissions": [
"activity",
"manage_keys",
"manage_languages",
"screenshots",
"branches_main_modify"
],
"description": "Create, translate and edit keys, manage screenshots",
"tag": "Advanced",
"tagColor": "cyan",
"doesEnableAllReadOnlyLanguages": true
},
{
"id": 4,
"role": "Reviewer",
"permissions": ["branches_main_modify", "review", "custom_status_modify"],
"description": "Translate keys, control key statuses",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
},
{
"id": 5,
"role": "Translator",
"permissions": ["branches_main_modify"],
"description": "Translate keys",
"tag": "Basic",
"tagColor": "grey",
"doesEnableAllReadOnlyLanguages": false
}
]
}
6 changes: 4 additions & 2 deletions test/fixtures/user_groups/list.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"created_at_timestamp": 1695130000,
"team_id": 176692,
"projects": [],
"members": []
"members": [],
"role_id": 5
},
{
"group_id": 7561,
Expand Down Expand Up @@ -42,7 +43,8 @@
"created_at_timestamp": 1659363404,
"team_id": 176692,
"projects": [],
"members": [34051, 71999]
"members": [34051, 71999],
"role_id": null
}
]
}
6 changes: 4 additions & 2 deletions test/fixtures/user_groups/list_pagination.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"created_at_timestamp": 1593176901,
"team_id": 176692,
"projects": [],
"members": []
"members": [],
"role_id": 5
},
{
"group_id": 9769,
Expand All @@ -43,7 +44,8 @@
"created_at_timestamp": 1689701755,
"team_id": 176692,
"projects": [],
"members": []
"members": [],
"role_id": null
}
]
}
3 changes: 2 additions & 1 deletion test/fixtures/user_groups/retrieve.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"created_at_timestamp": 1659363404,
"team_id": 176692,
"projects": [],
"members": [34051, 71999]
"members": [34051, 71999],
"role_id": 5
}
3 changes: 3 additions & 0 deletions test/user_groups/user_groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe("UserGroups", () => {
});

expect(user_groups.items[0].group_id).to.eq(2500);
expect(user_groups.items[0].role_id).to.eq(5);
expect(user_groups.items[1].role_id).to.eq(null);
expect(user_groups.totalResults).to.eq(4);
expect(user_groups.totalPages).to.eq(2);
expect(user_groups.resultsPerPage).to.eq(2);
Expand Down Expand Up @@ -92,6 +94,7 @@ describe("UserGroups", () => {
expect(user_group.team_id).to.eq(teamId);
expect(user_group.projects).to.have.lengthOf(0);
expect(user_group.members).to.include(34051);
expect(user_group.role_id).to.eq(5);
});

it("creates", async () => {
Expand Down
18 changes: 9 additions & 9 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineConfig } from 'tsup';
import { defineConfig } from "tsup";

export default defineConfig({
entry: ['src/main.ts'],
outDir: 'dist',
format: ['esm'],
dts: true,
splitting: false,
shims: true,
sourcemap: true,
clean: true,
entry: ["src/main.ts"],
outDir: "dist",
format: ["esm"],
dts: true,
splitting: false,
shims: true,
sourcemap: true,
clean: true,
});

0 comments on commit 1d22502

Please sign in to comment.