44 "context"
55 "testing"
66
7+ "github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/dto"
78 "github.com/stretchr/testify/assert"
89)
910
@@ -17,14 +18,14 @@ func TestSave(t *testing.T) {
1718 Title : "Trello API" ,
1819 Description : "API for Trello" ,
1920 Type : "1" ,
20- Md5sum : "d1092341234 " ,
21+ Md5sum : "981734bf " ,
2122 Url : "test_url" ,
2223 Groups : groups ,
2324 ApiMethods : apiMeth ,
2425 }
2526 rep := AsdRepositoryImpl {db : gDb }
2627 id , err := rep .Save (context .Background (), & entity )
27- assert .False (t , id == 0 )
28+ assert .True (t , id == entity . ID )
2829 assert .Nil (t , err )
2930}
3031
@@ -51,28 +52,27 @@ func TestDelete(t *testing.T) {
5152 Title : "Trello API" ,
5253 Description : "API for Trello" ,
5354 Type : "1" ,
54- Md5sum : "d1092341234 " ,
55+ Md5sum : "pook943 " ,
5556 Groups : groups ,
57+ Url : "www.trello.com" ,
5658 ApiMethods : apiMeth ,
5759 }
58- rep := RepositoryImpl {db : gDb }
59- err := rep .Save (context .Background (), & entity )
60+ rep := AsdRepositoryImpl {db : gDb }
61+ id , err := rep .Save (context .Background (), & entity )
6062 assert .Nil (t , err )
63+ assert .True (t , id == entity .ID )
6164 result , err := rep .FindById (context .Background (), entity .ID )
62- if err != nil {
63- t .Error (err )
64- }
65+ assert .Nil (t , err )
6566 assert .NotNil (t , result )
67+ assert .True (t , result .ID == entity .ID )
6668 err = rep .Delete (context .Background (), & entity )
6769 assert .Nil (t , err )
6870 result , err = rep .FindById (context .Background (), entity .ID )
69- if err != nil {
70- t .Error (err )
71- }
71+ assert .Nil (t , err )
7272 assert .Nil (t , result )
7373}
7474
75- func TestFindById (t * testing.T ) {
75+ func TestUpdate (t * testing.T ) {
7676 servG := []* Server {{URL : "test gr url" , Description : "test description G" }}
7777 apiMethG := []* ApiMethod {{Path : "test/path" , Name : "test name" , Servers : servG }}
7878 groups := []* Group {{Name : "test name" , ApiMethods : apiMethG }}
@@ -82,15 +82,57 @@ func TestFindById(t *testing.T) {
8282 Title : "Trello API" ,
8383 Description : "API for Trello" ,
8484 Type : "1" ,
85- Md5sum : "d1092341234" ,
85+ Md5sum : "jjujwadk2" ,
86+ Groups : groups ,
87+ Url : "wwww.trello.com" ,
88+ ApiMethods : apiMeth ,
89+ }
90+ rep := AsdRepositoryImpl {db : gDb }
91+ id , err := rep .Save (context .Background (), & entity )
92+ assert .Nil (t , err )
93+ assert .True (t , id == entity .ID )
94+ servG = []* Server {{URL : "test google url" , Description : "test description Google" }}
95+ apiMethG = []* ApiMethod {{Path : "test/path" , Name : "test Google" , Servers : servG }}
96+ groups = []* Group {{Name : "test google" , ApiMethods : apiMethG }}
97+ servs = []* Server {{URL : "test servG" , Description : "test Goggle 2" }}
98+ apiMeth = []* ApiMethod {{Path : "test2/path" , Name : "second test method" , Servers : servs }}
99+ entity = ApiSpecDoc {
100+ Title : "Google API" ,
101+ Description : "API for Google" ,
102+ Type : "2" ,
103+ Md5sum : "290384hrfi" ,
86104 Groups : groups ,
105+ Url : "wwww.google.com" ,
87106 ApiMethods : apiMeth ,
88107 }
89- rep := RepositoryImpl {db : gDb }
90- err := rep .Save (context .Background (), & entity )
91- if err != nil {
92- t .Error (err )
108+ err = rep .Update (context .Background (), & entity )
109+ assert .Nil (t , err )
110+ result , err := rep .FindById (context .Background (), entity .ID )
111+ assert .Nil (t , err )
112+ assert .NotNil (t , result )
113+ assert .True (t , entity .ID == result .ID )
114+ assert .True (t , entity .Title == result .Title )
115+ }
116+
117+ func TestFindById (t * testing.T ) {
118+ servG := []* Server {{URL : "test gr url" , Description : "test description G" }}
119+ apiMethG := []* ApiMethod {{Path : "test/path" , Name : "test name" , Servers : servG }}
120+ groups := []* Group {{Name : "test name" , ApiMethods : apiMethG }}
121+ servs := []* Server {{URL : "test servG" , Description : "test description 2" }}
122+ apiMeth := []* ApiMethod {{Path : "test2/path" , Name : "second test method" , Servers : servs }}
123+ entity := ApiSpecDoc {
124+ Title : "Trello API" ,
125+ Description : "API for Trello" ,
126+ Type : "1" ,
127+ Md5sum : "lkasjhdl343125" ,
128+ Groups : groups ,
129+ Url : "wwwww.trello.com" ,
130+ ApiMethods : apiMeth ,
93131 }
132+ rep := AsdRepositoryImpl {db : gDb }
133+ id , err := rep .Save (context .Background (), & entity )
134+ assert .Nil (t , err )
135+ assert .True (t , id == entity .ID )
94136 servG = []* Server {{URL : "test google url" , Description : "test description Google" }}
95137 apiMethG = []* ApiMethod {{Path : "test/path" , Name : "test Google" , Servers : servG }}
96138 groups = []* Group {{Name : "test google" , ApiMethods : apiMethG }}
@@ -100,17 +142,75 @@ func TestFindById(t *testing.T) {
100142 Title : "Google API" ,
101143 Description : "API for Google" ,
102144 Type : "2" ,
103- Md5sum : "i1oj234981 " ,
145+ Md5sum : "109238hrfeaslfuh " ,
104146 Groups : groups ,
147+ Url : "www.google.com" ,
105148 ApiMethods : apiMeth ,
106149 }
107- err = rep .Save (context .Background (), & entity )
150+ id , err = rep .Save (context .Background (), & entity )
151+ assert .Nil (t , err )
152+ assert .True (t , id == entity .ID )
153+ result , err := rep .FindById (context .Background (), entity .ID )
154+ assert .Nil (t , err )
155+ assert .NotNil (t , result )
156+ assert .True (t , result .ID == entity .ID )
157+ assert .True (t , result .Type == entity .Type )
158+ }
159+
160+ func TestFindByHash (t * testing.T ) {
161+ servG := []* Server {{URL : "test gr url" , Description : "test description G" }}
162+ apiMethG := []* ApiMethod {{Path : "test/path" , Name : "test name" , Servers : servG }}
163+ groups := []* Group {{Name : "test name" , ApiMethods : apiMethG }}
164+ servs := []* Server {{URL : "test servG" , Description : "test description 2" }}
165+ apiMeth := []* ApiMethod {{Path : "test2/path" , Name : "second test method" , Servers : servs }}
166+ entity := ApiSpecDoc {
167+ Title : "Trello API" ,
168+ Description : "API for Trello" ,
169+ Type : "1" ,
170+ Md5sum : "595f44fec1e92a71d3e9e77456ba80d1" ,
171+ Groups : groups ,
172+ Url : "wwwwww.trello.com" ,
173+ ApiMethods : apiMeth ,
174+ }
175+ rep := AsdRepositoryImpl {db : gDb }
176+ id , err := rep .Save (context .Background (), & entity )
177+ assert .Nil (t , err )
178+ assert .True (t , id == entity .ID )
179+ result , err := rep .FindByHash (context .Background (), "595f44fec1e92a71d3e9e77456ba80d1" )
108180 assert .Nil (t , err )
109- result , _ := rep .FindById (context .Background (), entity .ID )
110181 assert .NotNil (t , result )
182+ assert .True (t , result .Md5sum == entity .Md5sum )
183+ assert .True (t , result .ID == entity .ID )
184+ }
185+
186+ func TestFindByUrl (t * testing.T ) {
187+ servG := []* Server {{URL : "test gr url" , Description : "test description G" }}
188+ apiMethG := []* ApiMethod {{Path : "test/path" , Name : "test name" , Servers : servG }}
189+ groups := []* Group {{Name : "test name" , ApiMethods : apiMethG }}
190+ servs := []* Server {{URL : "test servG" , Description : "test description 2" }}
191+ apiMeth := []* ApiMethod {{Path : "test2/path" , Name : "second test method" , Servers : servs }}
192+ entity := ApiSpecDoc {
193+ Title : "Trello API" ,
194+ Description : "API for Trello" ,
195+ Type : "1" ,
196+ Md5sum : "95f44fec1e92a71d3e9e77456ba80d1" ,
197+ Groups : groups ,
198+ Url : "wwwwwww.trello.com" ,
199+ ApiMethods : apiMeth ,
200+ }
201+ rep := AsdRepositoryImpl {db : gDb }
202+ id , err := rep .Save (context .Background (), & entity )
203+ assert .Nil (t , err )
204+ assert .True (t , id == entity .ID )
205+ result , err := rep .FindByUrl (context .Background (), "wwwwwww.trello.com" )
206+ assert .Nil (t , err )
207+ assert .NotNil (t , result )
208+ assert .True (t , result .Url == entity .Url )
209+ assert .True (t , result .ID == entity .ID )
111210}
112211
113212func TestSearchShort (t * testing.T ) {
213+ t .Skip ("generics" )
114214 servG := []* Server {{URL : "google.com" , Description : "test description Google" }}
115215 apiMethG := []* ApiMethod {{Path : "test/path" , Name : "test Google" , Servers : servG }}
116216 groups := []* Group {{Name : "test google" , ApiMethods : apiMethG }}
@@ -120,16 +220,17 @@ func TestSearchShort(t *testing.T) {
120220 Title : "Google API" ,
121221 Description : "API for Google" ,
122222 Type : "2" ,
123- Md5sum : "i1oj234981 " ,
223+ Md5sum : "lkjafs871324r " ,
124224 Groups : groups ,
225+ Url : "wwww.google.com" ,
125226 ApiMethods : apiMeth ,
126227 }
127- rep := RepositoryImpl {db : gDb }
128- err := rep .Save (context .Background (), & entity )
228+ rep := AsdRepositoryImpl {db : gDb }
229+ id , err := rep .Save (context .Background (), & entity )
230+ number := dto.PageRequest {Page : 1 }
231+ assert .Nil (t , err )
232+ assert .True (t , id == entity .ID )
233+ result , err := rep .SearchShort (context .Background (), "Google" , number )
129234 assert .Nil (t , err )
130- result , err := rep .SearchShort (context .Background (), "Google" )
131- if err != nil {
132- t .Error (err )
133- }
134235 assert .NotNil (t , result )
135236}
0 commit comments