-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
64 lines (51 loc) · 1.55 KB
/
delete_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"form3-accountapi-client/uuid"
"gopkg.in/h2non/gock.v1"
"net/http"
"testing"
)
func Test_accountClient_Delete_ok_or_non_existent(t *testing.T) {
// arrange
accountId := uuid.MustUUID(uuid.FromStringV4("ad27e265-9605-4b4b-a0e5-3003ea9cc4dd"))
accountVersion := int64(0)
defer gock.Off()
gock.New("http://server.com").
Delete("/v1/organisation/accounts/" + accountId.String()).
Reply(http.StatusNoContent).
BodyString("")
accountClient, err := NewAccountClient("http", "server.com", 80, 1)
if err != nil {
t.Errorf("expected no error but got %v", err)
}
// act
err = accountClient.Delete(context.TODO(), accountId, accountVersion)
//assert
if _, ok := err.(ErrDuplicateAccount); ok {
t.Errorf("expected duplicate account failure but was %v", err)
}
}
func Test_accountClient_Delete_existing_non_existent_version(t *testing.T) {
// arrange
accountId := uuid.MustUUID(uuid.FromStringV4("ad27e265-9605-4b4b-a0e5-3003ea9cc4dd"))
accountVersion := int64(99)
response := `{
"error_message": "invalid version"
}`
defer gock.Off()
gock.New("http://server.com").
Delete("/v1/organisation/accounts/" + accountId.String()).
Reply(http.StatusNotFound).
BodyString(response)
accountClient, err := NewAccountClient("http", "server.com", 80, 1)
if err != nil {
t.Errorf("expected no error but got %v", err)
}
// act
err = accountClient.Delete(context.TODO(), accountId, accountVersion)
//assert
if _, ok := err.(ErrBadAccountRequest); ok {
t.Errorf("expected bad request failure but was %v", err)
}
}