-
Notifications
You must be signed in to change notification settings - Fork 2
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
8 changed files
with
160 additions
and
0 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,21 @@ | ||
package collections_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
approvals "github.com/approvals/go-approval-tests" | ||
"github.com/karngyan/maek/ui_api/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCreate(t *testing.T) { | ||
defer testutil.TruncateTables() | ||
cs := testutil.NewClientStateWithUser(t) | ||
|
||
rr, err := cs.Post(fmt.Sprintf("/v1/workspaces/%d/collections", cs.Workspace.ID), nil) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 201, rr.Code) | ||
|
||
approvals.VerifyJSONBytes(t, rr.Body.Bytes()) | ||
} |
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 collections_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
approvals "github.com/approvals/go-approval-tests" | ||
"github.com/karngyan/maek/domains/collections" | ||
"github.com/karngyan/maek/ui_api/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGet(t *testing.T) { | ||
defer testutil.TruncateTables() | ||
|
||
cs := testutil.NewClientStateWithUser(t) | ||
cs2 := testutil.NewClientStateWithUserEmail(t, "[email protected]") | ||
|
||
n, err := collections.CreateCollection(context.Background(), cs.Workspace.ID, cs.User.ID) | ||
assert.Nil(t, err) | ||
|
||
n2, err := collections.CreateCollection(context.Background(), cs2.Workspace.ID, cs2.User.ID) | ||
|
||
assert.Nil(t, err) | ||
|
||
var testCases = []struct { | ||
name string | ||
id int64 | ||
workspaceId int64 | ||
expectedStatus int | ||
}{ | ||
{ | ||
name: "valid collection id", | ||
id: n.ID, | ||
workspaceId: cs.Workspace.ID, | ||
expectedStatus: 200, | ||
}, | ||
{ | ||
name: "invalid collection id", | ||
id: -1, | ||
workspaceId: cs.Workspace.ID, | ||
expectedStatus: 400, | ||
}, | ||
{ | ||
name: "not found collection id", | ||
id: 5, | ||
workspaceId: cs.Workspace.ID, | ||
expectedStatus: 404, | ||
}, | ||
{ | ||
name: "collection id from different workspace", | ||
id: n2.ID, | ||
workspaceId: cs.Workspace.ID, | ||
expectedStatus: 404, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
rr, err := cs.Get(fmt.Sprintf("/v1/workspaces/%d/collections/%d", tc.workspaceId, tc.id)) | ||
assert.Nil(t, err) | ||
assert.Equal(t, tc.expectedStatus, rr.Code) | ||
|
||
approvals.VerifyJSONBytes(t, rr.Body.Bytes()) | ||
}) | ||
} | ||
} |
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,36 @@ | ||
package collections_test | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/approvals/go-approval-tests/reporters" | ||
|
||
approvals "github.com/approvals/go-approval-tests" | ||
|
||
"github.com/karngyan/maek/ui_api/testutil" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
testutil.FreezeTime() | ||
os.Exit(runTests(m)) | ||
} | ||
|
||
func runTests(m *testing.M) int { | ||
testApp, err := testutil.StartTestApp() | ||
if err != nil { | ||
log.Println("Error initializing test app: ", err) | ||
return 1 | ||
} | ||
defer func() { | ||
if err := testApp.Stop(); err != nil { | ||
log.Println("Error stopping test app: ", err) | ||
} | ||
}() | ||
|
||
approvals.UseFolder("./testdata") | ||
approvals.UseReporter(reporters.NewQuietReporter()) | ||
|
||
return m.Run() | ||
} |
13 changes: 13 additions & 0 deletions
13
ui_api/collections/testdata/create_test.TestCreate.approved.json
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,13 @@ | ||
{ | ||
"collection": { | ||
"created": 1234567890, | ||
"createdById": 1, | ||
"description": "", | ||
"id": 1, | ||
"name": "", | ||
"trashed": false, | ||
"updated": 1234567890, | ||
"updatedById": 1, | ||
"workspaceId": 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ollections/testdata/get_test.TestGet.collection_id_from_different_workspace.approved.json
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,3 @@ | ||
{ | ||
"error": "Collection not found" | ||
} |
3 changes: 3 additions & 0 deletions
3
ui_api/collections/testdata/get_test.TestGet.invalid_collection_id.approved.json
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,3 @@ | ||
{ | ||
"note_uuid": "collection_id is required" | ||
} |
3 changes: 3 additions & 0 deletions
3
ui_api/collections/testdata/get_test.TestGet.not_found_collection_id.approved.json
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,3 @@ | ||
{ | ||
"error": "Collection not found" | ||
} |
13 changes: 13 additions & 0 deletions
13
ui_api/collections/testdata/get_test.TestGet.valid_collection_id.approved.json
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,13 @@ | ||
{ | ||
"collection": { | ||
"created": 1234567890, | ||
"createdById": 1, | ||
"description": "", | ||
"id": 1, | ||
"name": "", | ||
"trashed": false, | ||
"updated": 1234567890, | ||
"updatedById": 1, | ||
"workspaceId": 1 | ||
} | ||
} |