-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
92 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package malak | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCounter(t *testing.T) { | ||
|
||
tt := []struct { | ||
name string | ||
amount int64 | ||
takeN int64 | ||
hasError bool | ||
}{ | ||
{ | ||
name: "cannot take from an empty counter", | ||
amount: 0, | ||
takeN: 10, | ||
hasError: true, | ||
}, | ||
{ | ||
name: "cannot take more than avaialble", | ||
amount: 10, | ||
takeN: 11, | ||
hasError: true, | ||
}, | ||
{ | ||
name: "can take exact value", | ||
amount: 10, | ||
takeN: 10, | ||
hasError: false, | ||
}, | ||
{ | ||
name: "can take less value", | ||
amount: 10, | ||
takeN: 9, | ||
hasError: false, | ||
}, | ||
{ | ||
name: "zero take 1", | ||
amount: 0, | ||
takeN: 1, | ||
hasError: true, | ||
}, | ||
{ | ||
name: "zero take 0", | ||
amount: 0, | ||
takeN: 0, | ||
hasError: true, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
c := Counter(tc.amount) | ||
err := c.TakeN(tc.takeN) | ||
|
||
if tc.hasError { | ||
require.Error(t, err) | ||
return | ||
} | ||
|
||
require.NoError(t, err) | ||
}) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
server/testdata/TestAuthHandler_FetchCurrentUser/listed_workspaces.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"user":{"id":"00000000-0000-0000-0000-000000000000","email":"","full_name":"","metadata":null,"roles":null,"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"workspaces":[{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oops","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oopskfjk","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"}],"message":"user data successfully retrieved"} | ||
{"user":{"id":"00000000-0000-0000-0000-000000000000","email":"","full_name":"","metadata":null,"roles":null,"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"workspaces":[{"id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oops","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},{"id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oopskfjk","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"}],"message":"user data successfully retrieved"} |
2 changes: 1 addition & 1 deletion
2
...testdata/TestAuthHandler_FetchCurrentUser/listed_workspaces_with_current_workspace.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"user":{"id":"00000000-0000-0000-0000-000000000000","email":"","full_name":"","metadata":null,"roles":null,"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"workspaces":[{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oops","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oopskfjk","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"}],"message":"user data successfully retrieved"} | ||
{"user":{"id":"00000000-0000-0000-0000-000000000000","email":"","full_name":"","metadata":null,"roles":null,"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"workspaces":[{"id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oops","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},{"id":"00000000-0000-0000-0000-000000000000","reference":"workspace_oopskfjk","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"}],"message":"user data successfully retrieved"} |
1 change: 0 additions & 1 deletion
1
server/testdata/TestContactHandler_GetSingleContact/get_contact_fails.golden
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
server/testdata/TestDeckHandler_UploadImage/file_upload_failed.golden
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
server/testdata/TestDeckHandler_UploadImage/no_file_uploaded.golden
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
server/testdata/TestUpdatesHandler_PreviewUpdate/error_creating_preview.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"message":"could not send update"} | ||
{"message":"could not send update to recipients"} |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
server/testdata/TestWorkspaceHandler_Create/created_workspace.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","workspace_name":"workspance name","plan_id":"00000000-0000-0000-0000-000000000000","reference":"workspace_tt7-YieIgz","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace successfully created"} | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","workspace_name":"workspance name","reference":"workspace_tt7-YieIgz","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace successfully created"} |
2 changes: 1 addition & 1 deletion
2
server/testdata/TestWorkspaceHandler_SwitchWorkspace/updated_current_workspace.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"user's default workspace updated"} | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"user's default workspace updated"} |
2 changes: 1 addition & 1 deletion
2
server/testdata/TestWorkspaceHandler_Update/update_succeeds.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","workspace_name":"12345","plan_id":"00000000-0000-0000-0000-000000000000","timezone":"Africa/Algiers","logo_url":"https://images.unsplash.com/photo-1737467023078-a694673d7cb3","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","workspace_name":"12345","timezone":"Africa/Algiers","logo_url":"https://images.unsplash.com/photo-1737467023078-a694673d7cb3","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} |
2 changes: 1 addition & 1 deletion
2
...stdata/TestWorkspaceHandler_Update/update_succeeds_even_if_partial_fields_provided.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","timezone":"Africa/Algiers","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","timezone":"Africa/Algiers","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} |
2 changes: 1 addition & 1 deletion
2
server/testdata/TestWorkspaceHandler_Update/update_succeeds_if_no_fields_provided.golden
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 |
---|---|---|
@@ -1 +1 @@ | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} | ||
{"workspace":{"id":"00000000-0000-0000-0000-000000000000","plan_id":"00000000-0000-0000-0000-000000000000","metadata":{"team":{},"deck":{},"updates":{},"integrations":{},"dashboard":{},"data_room":{}},"created_at":"0001-01-01T00:00:00Z","updated_at":"0001-01-01T00:00:00Z"},"message":"workspace updated"} |
1 change: 0 additions & 1 deletion
1
...estdata/TestWorkspaceHandler_getIntegrations/could_not_fetch_workspace_preferences.golden
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -682,7 +682,7 @@ func generateUpdateTestTable() []struct { | |
expectedStatusCode: http.StatusInternalServerError, | ||
}, | ||
{ | ||
name: "error during update creation", | ||
name: "error during update sending", | ||
mockFn: func(update *malak_mocks.MockUpdateRepository) { | ||
update.EXPECT().Get(gomock.Any(), gomock.Any()).Return(&malak.Update{}, nil) | ||
update.EXPECT().SendUpdate(gomock.Any(), gomock.Any()).Return(errors.New("oops")) | ||
|
@@ -695,7 +695,7 @@ func generateUpdateTestTable() []struct { | |
expectedStatusCode: http.StatusInternalServerError, | ||
}, | ||
{ | ||
name: "successful update creation", | ||
name: "successful update sending", | ||
mockFn: func(update *malak_mocks.MockUpdateRepository) { | ||
update.EXPECT().Get(gomock.Any(), gomock.Any()).Return(&malak.Update{}, nil) | ||
update.EXPECT().SendUpdate(gomock.Any(), gomock.Any()).Return(nil) | ||
|
@@ -707,6 +707,20 @@ func generateUpdateTestTable() []struct { | |
}, | ||
expectedStatusCode: http.StatusOK, | ||
}, | ||
{ | ||
name: "update sending reached max recipients", | ||
mockFn: func(update *malak_mocks.MockUpdateRepository) { | ||
update.EXPECT().Get(gomock.Any(), gomock.Any()).Return(&malak.Update{}, nil) | ||
update.EXPECT().SendUpdate(gomock.Any(), gomock.Any()). | ||
Return(malak.ErrCounterExhausted) | ||
}, | ||
req: sendUpdateRequest{ | ||
Emails: []malak.Email{ | ||
"[email protected]", | ||
}, | ||
}, | ||
expectedStatusCode: http.StatusPaymentRequired, | ||
}, | ||
} | ||
} | ||
|
||
|