MCPcopy Create free account
hub / github.com/NextDotID/proof_server / Test_proofChainQuery

Function Test_proofChainQuery

controller/proof_chain_test.go:9–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func Test_proofChainQuery(t *testing.T) {
10 t.Run("success", func(t *testing.T) {
11 before_each(t)
12 insert_proof(t)
13 resp_body := ProofChainResponse{}
14 resp := APITestCall(
15 Engine,
16 "GET",
17 fmt.Sprintf("/v1/proofchain?public_key=%s", persona),
18 nil,
19 &resp_body,
20 )
21 assert.Equal(t, 200, resp.Code)
22 //t.Logf("%s", resp.Body.String())
23 assert.Equal(t, 2, len(resp_body.ProofChains))
24 })
25
26 t.Run("empty result", func(t *testing.T) {
27 before_each(t)
28 resp_body := ProofChainResponse{}
29 resp := APITestCall(
30 Engine,
31 "GET",
32 fmt.Sprintf("/v1/proofchain?public_key=%s", "aaa"),
33 nil,
34 &resp_body,
35 )
36 assert.Equal(t, 200, resp.Code)
37 //t.Logf("%s", resp.Body.String())
38 assert.Equal(t, 0, len(resp_body.ProofChains))
39 })
40
41 t.Run("patination", func(t *testing.T) {
42 before_each(t)
43 for i := 0; i < 22; i++ { // Create 44 records
44 insert_proof(t)
45 }
46 url := fmt.Sprintf("/v1/proofchain?public_key=%s", persona)
47
48 resp_page1 := ProofChainResponse{} // Page not given
49 APITestCall(Engine, "GET", url, nil, &resp_page1)
50 assert.Equal(t, int64(44), resp_page1.Pagination.Total)
51 assert.Equal(t, 1, resp_page1.Pagination.Current)
52 assert.Equal(t, 2, resp_page1.Pagination.Next)
53 assert.Equal(t, PER_PAGE, len(resp_page1.ProofChains))
54
55 resp_page3 := ProofChainResponse{} // Last page
56 APITestCall(Engine, "GET", url+"&page=3", nil, &resp_page3)
57 assert.Equal(t, 3, resp_page3.Pagination.Current)
58 assert.Equal(t, 0, resp_page3.Pagination.Next)
59 assert.Equal(t, 4, len(resp_page3.ProofChains))
60
61 resp_page4 := ProofChainResponse{} // Page overflow
62 APITestCall(Engine, "GET", url+"&page=4", nil, &resp_page4)
63 assert.Equal(t, 4, resp_page4.Pagination.Current)
64 assert.Equal(t, 0, resp_page4.Pagination.Next)
65 assert.Equal(t, 0, len(resp_page4.ProofChains))
66 })

Callers

nothing calls this directly

Calls 3

insert_proofFunction · 0.85
before_eachFunction · 0.70
APITestCallFunction · 0.70

Tested by

no test coverage detected