verification/tests/e2e/get_verify_admin_test.go
2024-11-21 10:29:18 +03:00

58 lines
1.4 KiB
Go

package e2e
import (
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"gitea.pena/PenaSide/verification/internal/models"
"gitea.pena/PenaSide/verification/tests/helpers"
"testing"
)
func Test_GetVerifyAdmin(t *testing.T) {
url := "http://localhost:8081/verification/64e53ed187392e122e5d3d50"
client := fiber.AcquireClient()
token, err := helpers.CreateJwt("64e53ed187392e122e5d3d51")
assert.NoError(t, err)
agent := client.Get(url)
agent.Set("Authorization", fmt.Sprintf("Bearer %s", token))
statusCode, respBody, errs := agent.Bytes()
if len(errs) > 0 {
assert.NoError(t, errs[0])
}
assert.Equal(t, 200, statusCode)
var resp models.Verification
err = json.Unmarshal(respBody, &resp)
assert.NoError(t, err)
fmt.Println(resp)
url = "http://localhost:8081/verification"
client2 := fiber.AcquireClient()
req := models.ReqSetVerification{
ID: resp.ID,
Status: "nko",
Comment: "MOLODEC, GOOD JOB",
Accepted: true,
TaxNumber: "000-000-000",
}
reqBody, err := json.Marshal(req)
assert.NoError(t, err)
agent2 := client2.Patch(url).Body(reqBody).ContentType("application/json")
agent2.Set("Authorization", fmt.Sprintf("Bearer %s", token))
statusCode, _, errs = agent2.Bytes()
if len(errs) > 0 {
fmt.Println(errs[0])
assert.NoError(t, errs[0])
}
assert.Equal(t, 200, statusCode)
}