github.com/kotovmak/go-admin@v1.1.1/tests/common/api.go (about)

     1  package common
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/gavv/httpexpect"
     8  	"github.com/kotovmak/go-admin/modules/config"
     9  	"github.com/kotovmak/go-admin/plugins/admin/modules/constant"
    10  )
    11  
    12  func apiTest(e *httpexpect.Expect, sesID *http.Cookie) {
    13  
    14  	fmt.Println()
    15  	printlnWithColor("Api", "blue")
    16  	fmt.Println("============================")
    17  
    18  	printlnWithColor("show", "green")
    19  	e.GET(config.Url("/api/list/manager")).
    20  		WithHeader("Accept", "application/json, text/plain, */*").
    21  		WithCookie(sesID.Name, sesID.Value).
    22  		Expect().
    23  		Status(200).JSON().Object().ValueEqual("code", 200)
    24  
    25  	//printlnWithColor("update form without id", "green")
    26  	//e.GET(config.Url("/api/edit/form/manager")).
    27  	//	WithHeader("Accept", "application/json, text/plain, */*").
    28  	//	WithCookie(sesID.Name, sesID.Value).
    29  	//	Expect().
    30  	//	Status(400).JSON().Object().ValueEqual("code", 400)
    31  
    32  	printlnWithColor("update form", "green")
    33  	e.GET(config.Url("/api/edit/form/manager")).
    34  		WithHeader("Accept", "application/json, text/plain, */*").
    35  		WithQuery(constant.EditPKKey, "1").
    36  		WithCookie(sesID.Name, sesID.Value).
    37  		Expect().
    38  		Status(200).JSON().Object().ValueEqual("code", 200)
    39  
    40  	printlnWithColor("create form", "green")
    41  	e.GET(config.Url("/api/create/form/manager")).
    42  		WithHeader("Accept", "application/json, text/plain, */*").
    43  		WithCookie(sesID.Name, sesID.Value).
    44  		Expect().
    45  		Status(200).JSON().Object().ValueEqual("code", 200)
    46  }