From bf99fbed6d7172a0e2f4c6808e692f9722a4c702 Mon Sep 17 00:00:00 2001 From: mamad Date: Mon, 2 Sep 2024 22:35:44 +0330 Subject: [PATCH] test(agent-kindbox-e2e): adding e2e test for "/agents/kindboxes" GET api --- .../http_server/end2end/agent_kindbox_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/delivery/http_server/end2end/agent_kindbox_test.go b/delivery/http_server/end2end/agent_kindbox_test.go index a9dd9df..2deebd0 100644 --- a/delivery/http_server/end2end/agent_kindbox_test.go +++ b/delivery/http_server/end2end/agent_kindbox_test.go @@ -100,6 +100,31 @@ func getToken() (string, error) { return res.Tokens.AccessToken, nil } +// TODO: if anyone add a new kindbox for this agent, then this test will fail because count will change. +// somehow we should link seed data with test data. +// maybe not use sql seed data and create data in each test +func TestAgent_KindBox_Get_All(t *testing.T) { + kindBoxesCount := 1 + + url := "/agents/kindboxes" + + teardown := setup.SeedMariaDB(testContainer.GetMariaDBConfig()) + t.Cleanup(teardown) + + token, err := getToken() + if err != nil { + t.Fatalf("could not login: %s", err) + } + + resRecord := createRequest(http.MethodGet, url, token, nil) + var res agentParam.GetAllResponse + err = json.NewDecoder(resRecord.Body).Decode(&res) + assert.NoError(t, err, "could not decode response body") + + assert.Equal(t, http.StatusOK, resRecord.Code) + assert.Equal(t, kindBoxesCount, len(res.AllKindBoxes)) +} + func createRequest( method string, url string,