From c9f394fe7fa0a5a6504b5b80ae7019cffdf4bb14 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 13 Mar 2025 16:43:47 -0600 Subject: refactor: extract authz interface to test out different PaC libraries --- test/e2e_test.go | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'test/e2e_test.go') 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"]) + }) }) }) -- cgit v1.2.3