Skip to content

Commit

Permalink
Add unit test for apps.GetAR
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonmichaque committed Aug 15, 2023
1 parent ad46d70 commit 313dfb5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
46 changes: 46 additions & 0 deletions apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,56 @@ func TestApps_Get(t *testing.T) {
assertApps(t, want, resp.Data)
}

func TestApps_GetAR(t *testing.T) {
srv := NewServer(t)
defer srv.Close()

token := "TOKEN"

srv.mux.HandleFunc("/portal-api/apps/1/access-requests/30", func(w http.ResponseWriter, r *http.Request) {
httpResponse := httpParse(t, "portal-api/get_ar_success.txt")
defer httpResponse.Body.Close()

assertMethod(t, "GET", r)
assertHeader(t, r, "Authorization", token)

w.WriteHeader(httpResponse.StatusCode)
_, err := io.Copy(w, httpResponse.Body)
assert.NoError(t, err)
})

client, err := New(
WithBaseURL(srv.srv.URL),
WithToken(token),
)
assert.NoError(t, err)

resp, err := client.Apps().GetAR(context.Background(), 1, 30)
assert.NoError(t, err)

want := &ARDetails{
Client: "v34",
Catalogue: "Public Catalogue",
Plan: "free_plan",
Products: []string{
"puvlic_product",
},
}

assertAR(t, want, resp.Data)
}

func assertApps(t *testing.T, want, got []App) {
require.Equal(t, len(want), len(got), "wanted len %v but got len", len(want), len(got))

for k, v := range want {
assert.Equal(t, v, got[k])
}
}

func assertAR(t *testing.T, want, got *ARDetails) {
assert.Equal(t, want.AuthType, got.AuthType, "wanted auth type %v but got %v", want.AuthType, got.AuthType)
assert.Equal(t, want.Catalogue, got.Catalogue, "wanted catalogue %v but got %v", want.Catalogue, got.Catalogue)
assert.Equal(t, want.Client, got.Client, "wanted client %v but got %v", want.Client, got.Client)
assert.Equal(t, want.Plan, got.Plan, "wanted plan %v but got %v", want.Plan, got.Plan)
}
38 changes: 38 additions & 0 deletions testdata/portal-api/get_ar_success.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HTTP/1.1 200 OK
Cache-Control: no-store
Content-Type: application/json
Pragma: no-cache
Date: Tue, 15 Aug 2023 19:42:37 GMT
Content-Length: 802

{
"Catalogue": "Public Catalogue",
"Client": "v34",
"CreatedAt": "2023-08-14 19:09",
"Credentials": [
{
"AccessRequest": "AccessRequest#30",
"Credential": "eyJvcmciOiI2MTcwMDZjMTgyOWI2ZjAwMDFjNmMwMzkiLCJpZCI6IjQ0ZDc1OWYwZGVjYzQ2MDliYmMxNDVjYjJkMTJhNjM4IiwiaCI6Im11cm11cjY0In0=",
"CredentialHash": "60bf6ae8aeddde79",
"DCRRegistrationAccessToken": "",
"DCRRegistrationClientURI": "",
"DCRResponse": "",
"Expires": "1970-01-01 02:00",
"GrantType": "",
"ID": 29,
"JWKSURI": "",
"OAuthClientID": "",
"OAuthClientSecret": "",
"RedirectURI": "",
"ResponseType": "",
"Scope": "",
"TokenEndpoints": ""
}
],
"DeletedAt": "",
"Plan": "free_plan",
"PolicyService": [],
"Products": "public_product",
"UpdatedAt": "2023-08-14 19:09",
"User": "User#1"
}

0 comments on commit 313dfb5

Please sign in to comment.