summaryrefslogtreecommitdiff
path: root/test/e2e_test.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-13 16:43:47 -0600
committermo khan <mo@mokhan.ca>2025-03-13 16:43:47 -0600
commitc9f394fe7fa0a5a6504b5b80ae7019cffdf4bb14 (patch)
treeda1ef1c59264221c2c483ddd76401ee19cd1015c /test/e2e_test.go
parentb55a6617971fa50bb064480f78343e6c0bc59dbe (diff)
refactor: extract authz interface to test out different PaC libraries
Diffstat (limited to 'test/e2e_test.go')
-rw-r--r--test/e2e_test.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/test/e2e_test.go b/test/e2e_test.go
index b465d76..7e98b1b 100644
--- a/test/e2e_test.go
+++ b/test/e2e_test.go
@@ -80,19 +80,41 @@ func TestAuthx(t *testing.T) {
assert.Equal(t, "Bearer", item.TokenType)
assert.NotEmpty(t, item.RefreshToken)
- response := x.Must(http.Get("http://api.example.com:8080/projects.json"))
- assert.Equal(t, http.StatusOK, response.StatusCode)
- projects := x.Must(serde.FromJSON[[]map[string]string](response.Body))
- assert.NotNil(t, projects)
-
- io := bytes.NewBuffer(nil)
- assert.NoError(t, serde.ToJSON(io, map[string]string{"name": "example"}))
- request := x.Must(http.NewRequestWithContext(t.Context(), "POST", "http://api.example.com:8080/projects", io))
- request.Header.Add("Authorization", "Bearer "+item.AccessToken)
- response = x.Must(client.Do(request))
- assert.Equal(t, http.StatusCreated, response.StatusCode)
- project := x.Must(serde.FromJSON[map[string]string](response.Body))
- assert.Equal(t, "example", project["name"])
+ t.Run("lists all the organizations", func(t *testing.T) {
+ response := x.Must(http.Get("http://api.example.com:8080/organizations.json"))
+ assert.Equal(t, http.StatusOK, response.StatusCode)
+ organizations := x.Must(serde.FromJSON[[]map[string]string](response.Body))
+ assert.NotNil(t, organizations)
+ })
+
+ t.Run("lists all the projects", func(t *testing.T) {
+ response := x.Must(http.Get("http://api.example.com:8080/projects.json"))
+ assert.Equal(t, http.StatusOK, response.StatusCode)
+ projects := x.Must(serde.FromJSON[[]map[string]string](response.Body))
+ assert.NotNil(t, projects)
+ })
+
+ t.Run("creates a new project", func(t *testing.T) {
+ io := bytes.NewBuffer(nil)
+ assert.NoError(t, serde.ToJSON(io, map[string]string{"name": "example"}))
+ request := x.Must(http.NewRequestWithContext(t.Context(), "POST", "http://api.example.com:8080/projects", io))
+ request.Header.Add("Authorization", "Bearer "+item.AccessToken)
+ response := x.Must(client.Do(request))
+ assert.Equal(t, http.StatusCreated, response.StatusCode)
+ project := x.Must(serde.FromJSON[map[string]string](response.Body))
+ assert.Equal(t, "example", project["name"])
+ })
+
+ t.Run("creates another projects", func(t *testing.T) {
+ io := bytes.NewBuffer(nil)
+ assert.NoError(t, serde.ToJSON(io, map[string]string{"name": "example2"}))
+ request := x.Must(http.NewRequestWithContext(t.Context(), "POST", "http://api.example.com:8080/projects.json", io))
+ request.Header.Add("Authorization", "Bearer "+item.AccessToken)
+ response := x.Must(client.Do(request))
+ assert.Equal(t, http.StatusCreated, response.StatusCode)
+ project := x.Must(serde.FromJSON[map[string]string](response.Body))
+ assert.Equal(t, "example2", project["name"])
+ })
})
})