-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HOME-1781: extracted templates separately, added tests
- Loading branch information
1 parent
b6d5cbf
commit 6a75066
Showing
5 changed files
with
131 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package lokalise | ||
|
||
import "fmt" | ||
|
||
const ( | ||
pathTemplates = "teams/%d/roles" | ||
) | ||
|
||
// The PermissionTemplate service | ||
type PermissionTemplateService struct { | ||
BaseService | ||
} | ||
|
||
type PermissionTemplate struct { | ||
ID int `json:"id"` | ||
Role string `json:"role"` | ||
Permissions []string `json:"permissions"` | ||
Description string `json:"description"` | ||
Tag string `json:"tag"` | ||
TagColor string `json:"tagColor"` | ||
TagInfo string `json:"tagInfo"` | ||
DoesEnableAllReadOnlyLanguages bool `json:"doesEnableAllReadOnlyLanguages"` | ||
} | ||
|
||
type PermissionRoleResponse struct { | ||
Roles []PermissionTemplate `json:"roles"` | ||
} | ||
|
||
// List all possible permission roles | ||
func (c *PermissionTemplateService) ListPermissionRoles(teamID int64) (r PermissionRoleResponse, err error) { | ||
resp, err := c.getWithOptions(c.Ctx(), pathPermissionRoles(teamID), &r, c.PageOpts()) | ||
|
||
if err != nil { | ||
return r, err | ||
} | ||
return r, apiError(resp) | ||
} | ||
|
||
func pathPermissionRoles(teamID int64) string { | ||
return fmt.Sprintf(pathTemplates, teamID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package lokalise | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestTeamPermissionTemplates_List(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
mux.HandleFunc( | ||
"/teams/1/roles", | ||
func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
testMethod(t, r, "GET") | ||
testHeader(t, r, apiTokenHeader, testApiToken) | ||
|
||
_, _ = fmt.Fprint(w, `{ | ||
"roles": [ | ||
{ | ||
"id": 1, | ||
"role": "Localisation management", | ||
"permissions": [ | ||
"activity", | ||
"branches_main_modify" | ||
], | ||
"description": "Manage project settings, contributors and tasks", | ||
"tag": "Full access", | ||
"tagColor": "green", | ||
"doesEnableAllReadOnlyLanguages": true | ||
}, | ||
{ | ||
"id": 2, | ||
"role": "Developer", | ||
"permissions": [ | ||
"download", | ||
"upload" | ||
], | ||
"description": "Create keys, upload and download content", | ||
"tag": "Advanced", | ||
"tagColor": "cyan", | ||
"doesEnableAllReadOnlyLanguages": true | ||
} | ||
] | ||
}`) | ||
}) | ||
|
||
r, err := client.PermissionTemplates().ListPermissionRoles(1) | ||
if err != nil { | ||
t.Errorf("Teams.List returned error: %v", err) | ||
} | ||
|
||
want := PermissionRoleResponse{ | ||
Roles: []PermissionTemplate{ | ||
{ | ||
ID: 1, | ||
Role: "Localisation management", | ||
Permissions: []string{ | ||
"activity", | ||
"branches_main_modify", | ||
}, | ||
Description: "Manage project settings, contributors and tasks", | ||
Tag: "Full access", | ||
TagColor: "green", | ||
DoesEnableAllReadOnlyLanguages: true, | ||
}, | ||
{ | ||
ID: 2, | ||
Role: "Developer", | ||
Permissions: []string{ | ||
"download", | ||
"upload", | ||
}, | ||
Description: "Create keys, upload and download content", | ||
Tag: "Advanced", | ||
TagColor: "cyan", | ||
DoesEnableAllReadOnlyLanguages: true, | ||
}, | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(r, want) { | ||
t.Errorf("Team.PermissionRoles.List returned %+v, want %+v", r, want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters