Skip to content

Commit

Permalink
test: add unit tests for Source Strings methods (#22)
Browse files Browse the repository at this point in the history
* chore(source strings): replace int64 with int

* test: add unit tests for Source Strings methods

* style(source strings): apply gofmt
  • Loading branch information
vorobeyme committed Apr 17, 2024
1 parent a1b65f2 commit 35ceba4
Show file tree
Hide file tree
Showing 3 changed files with 906 additions and 27 deletions.
39 changes: 20 additions & 19 deletions crowdin/model/source_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ import (

// SourceString represents the text units for translation.
type SourceString struct {
ID int `json:"id"`
ProjectID int `json:"projectId"`
BranchID *int `json:"branchId,omitempty"`
Identifier string `json:"identifier"`
Text string `json:"text"`
Type string `json:"type"`
Context string `json:"context"`
MaxLength int `json:"maxLength"`
IsHidden bool `json:"isHidden"`
IsDuplicate bool `json:"isDuplicate"`
MasterStringID *int `json:"masterStringId,omitempty"`
LabelIDs []int `json:"labelIds"`
WebURL string `json:"webUrl"`
CreatedAt *string `json:"createdAt,omitempty"`
UpdatedAt *string `json:"updatedAt,omitempty"`
FileID int `json:"fileId"`
DirectoryID *int `json:"directoryId,omitempty"`
Revision int `json:"revision"`
ID int `json:"id"`
ProjectID int `json:"projectId"`
BranchID *int `json:"branchId,omitempty"`
Identifier string `json:"identifier"`
Text string `json:"text"`
Type string `json:"type"`
Context string `json:"context"`
MaxLength int `json:"maxLength"`
IsHidden bool `json:"isHidden"`
IsDuplicate bool `json:"isDuplicate"`
MasterStringID *int `json:"masterStringId,omitempty"`
LabelIDs []int `json:"labelIds"`
WebURL string `json:"webUrl"`
CreatedAt *string `json:"createdAt,omitempty"`
UpdatedAt *string `json:"updatedAt,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
FileID *int `json:"fileId,omitempty"`
DirectoryID *int `json:"directoryId,omitempty"`
Revision *int `json:"revision,omitempty"`
}

// SourceStringsGetResponse describes the response when getting
Expand Down Expand Up @@ -193,7 +194,7 @@ type SourceStringsUpload struct {
Progress int `json:"progress"`
Attributes struct {
BranchID int `json:"branchId"`
SotrageID int `json:"storageId"`
StorageID int `json:"storageId"`
FileType string `json:"fileType"`
ParserVersion int `json:"parserVersion"`
LabelIDs []int `json:"labelIds"`
Expand Down
16 changes: 8 additions & 8 deletions crowdin/source_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type SourceStringsService struct {
// Use optional parameters to filter the list.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.getMany
func (s *SourceStringsService) List(ctx context.Context, projectID int64, opts *model.SourceStringsListOptions) (
func (s *SourceStringsService) List(ctx context.Context, projectID int, opts *model.SourceStringsListOptions) (
[]*model.SourceString, *Response, error,
) {
res := new(model.SourceStringsListResponse)
Expand All @@ -42,7 +42,7 @@ func (s *SourceStringsService) List(ctx context.Context, projectID int64, opts *
// Get returns a specific source string by its identifier.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.get
func (s *SourceStringsService) Get(ctx context.Context, projectID, stringID int64, opts *model.SourceStringsGetOptions) (
func (s *SourceStringsService) Get(ctx context.Context, projectID, stringID int, opts *model.SourceStringsGetOptions) (
*model.SourceString, *Response, error,
) {
res := new(model.SourceStringsGetResponse)
Expand All @@ -54,7 +54,7 @@ func (s *SourceStringsService) Get(ctx context.Context, projectID, stringID int6
// Add creates a new string.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.post
func (s *SourceStringsService) Add(ctx context.Context, projectID int64, req *model.SourceStringsAddRequest) (
func (s *SourceStringsService) Add(ctx context.Context, projectID int, req *model.SourceStringsAddRequest) (
*model.SourceString, *Response, error,
) {
res := new(model.SourceStringsGetResponse)
Expand All @@ -74,7 +74,7 @@ func (s *SourceStringsService) Add(ctx context.Context, projectID int64, req *mo
// boolean or map
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.batchPatch
func (s *SourceStringsService) BatchOperations(ctx context.Context, projectID int64, req []*model.UpdateRequest) (
func (s *SourceStringsService) BatchOperations(ctx context.Context, projectID int, req []*model.UpdateRequest) (
[]*model.SourceString, *Response, error,
) {
res := new(model.SourceStringsListResponse)
Expand Down Expand Up @@ -102,7 +102,7 @@ func (s *SourceStringsService) BatchOperations(ctx context.Context, projectID in
// boolean or object
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.patch
func (s *SourceStringsService) Edit(ctx context.Context, projectID, stringID int64, req []*model.UpdateRequest) (
func (s *SourceStringsService) Edit(ctx context.Context, projectID, stringID int, req []*model.UpdateRequest) (
*model.SourceString, *Response, error,
) {
res := new(model.SourceStringsGetResponse)
Expand All @@ -114,14 +114,14 @@ func (s *SourceStringsService) Edit(ctx context.Context, projectID, stringID int
// Delete removes a specific string by its identifier.
//
// https://developer.crowdin.com/api/v2/#operation/api.projects.strings.delete
func (s *SourceStringsService) Delete(ctx context.Context, projectID, stringID int64) (*Response, error) {
func (s *SourceStringsService) Delete(ctx context.Context, projectID, stringID int) (*Response, error) {
return s.client.Delete(ctx, fmt.Sprintf("/api/v2/projects/%d/strings/%d", projectID, stringID))
}

// GetUploadStatus returns the status of the uploaded strings.
//
// https://developer.crowdin.com/api/v2/string-based/#operation/api.projects.strings.uploads.get
func (s *SourceStringsService) GetUploadStatus(ctx context.Context, projectID int64, uploadID string) (
func (s *SourceStringsService) GetUploadStatus(ctx context.Context, projectID int, uploadID string) (
*model.SourceStringsUpload, *Response, error,
) {
res := new(model.SourceStringsUploadResponse)
Expand All @@ -133,7 +133,7 @@ func (s *SourceStringsService) GetUploadStatus(ctx context.Context, projectID in
// Upload uploads strings to the project.
//
// https://developer.crowdin.com/api/v2/string-based/#operation/api.projects.strings.uploads.post
func (s *SourceStringsService) Upload(ctx context.Context, projectID int64, req *model.SourceStringsUploadRequest) (
func (s *SourceStringsService) Upload(ctx context.Context, projectID int, req *model.SourceStringsUploadRequest) (
*model.SourceStringsUpload, *Response, error,
) {
res := new(model.SourceStringsUploadResponse)
Expand Down
Loading

0 comments on commit 35ceba4

Please sign in to comment.