package test import ( "bitbucket.org/skeris/heruvym/app" "bitbucket.org/skeris/heruvym/service" "bitbucket.org/skeris/profile/jwt_adapter" "bytes" "context" "encoding/json" "github.com/themakers/bdd" "net/http" "testing" "time" ) func TestTicket(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() bdd.Scenario(t, "SupportChat", func(t *testing.T, runID string) { go func () { _, err := app.New(ctx, app.Options{ MongoURI: "mongodb://localhost:27017", NumberPortLocal: "1488", LoggerDevMode: false, }) if err != nil { panic(err) } }() time.Sleep(time.Second * 2) bdd.Act(t, "client", func() { bdd.Test(t, "CreateTicket", func() { buf, err := json.Marshal(service.CreateTicketReq{ Title: "TestTitle", Message: "test", }) if err != nil { panic(err) } req, err :=http.NewRequestWithContext( ctx, "POST", "http://localhost:1488/create", bytes.NewBuffer(buf)) if err != nil { panic(err) } req.Header.Add(jwt_adapter.DefaultHeaderKey, "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJJRCI6ImMxcDM0YjhqZHBmOG04Zm43cnIwIiwiU2Vzc2lvbiI6ImMxcDM0YjhqZHBmOG04Zm43cnJnIiwiVXNlciI6IiIsIlRhcmlmZiI6MCwiQ3JlYXRlZCI6MTYxODA5NjY4NTc4MCwiTGFzdFNlZW4iOjE2MTgwOTY2ODU3ODF9.ciJoJiOxzIPv0LY4h3rG8Tf3AsSBXXLcYEpyN9mIki0") resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } if resp.StatusCode != http.StatusOK { panic("NotAccepted") } }) }) }) }