delete_place_test.go 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. package place
  2. import (
  3. "context"
  4. "database/sql"
  5. "errors"
  6. "net/http/httptest"
  7. "strconv"
  8. "testing"
  9. API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
  10. "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
  11. "git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
  12. "git.dmitriygnatenko.ru/dima/homethings/internal/interfaces"
  13. "git.dmitriygnatenko.ru/dima/homethings/internal/models"
  14. repoMocks "git.dmitriygnatenko.ru/dima/homethings/internal/repositories/mocks"
  15. sp "git.dmitriygnatenko.ru/dima/homethings/internal/service_provider"
  16. "github.com/brianvoe/gofakeit/v6"
  17. "github.com/gofiber/fiber/v2"
  18. "github.com/gojuno/minimock/v3"
  19. "github.com/stretchr/testify/assert"
  20. )
  21. func Test_DeletePlaceHandler(t *testing.T) {
  22. type req struct {
  23. method string
  24. route string
  25. }
  26. var (
  27. mc = minimock.NewController(t)
  28. placeID = gofakeit.Number(1, 1000)
  29. thingID = gofakeit.Number(1, 1000)
  30. placeImageID = gofakeit.Number(1, 1000)
  31. placeImageURL = gofakeit.URL()
  32. thingImageID = gofakeit.Number(1, 1000)
  33. thingImageURL = gofakeit.URL()
  34. testError = errors.New(gofakeit.Phrase())
  35. correctReq = req{
  36. method: fiber.MethodDelete,
  37. route: "/v1/places/" + strconv.Itoa(placeID),
  38. }
  39. thingRepoRes = []models.Thing{
  40. {
  41. ID: thingID,
  42. PlaceID: placeID,
  43. },
  44. }
  45. placeImageRepoRes = []models.Image{
  46. {
  47. ID: placeImageID,
  48. Image: placeImageURL,
  49. },
  50. }
  51. thingImageRepoRes = []models.Image{
  52. {
  53. ID: thingImageID,
  54. Image: thingImageURL,
  55. },
  56. }
  57. )
  58. tests := []struct {
  59. name string
  60. req req
  61. resCode int
  62. resBody interface{}
  63. placeRepoMock func(mc *minimock.Controller) interfaces.PlaceRepository
  64. thingRepoMock func(mc *minimock.Controller) interfaces.ThingRepository
  65. placeThingRepoMock func(mc *minimock.Controller) interfaces.PlaceThingRepository
  66. thingImageRepoMock func(mc *minimock.Controller) interfaces.ThingImageRepository
  67. placeImageRepoMock func(mc *minimock.Controller) interfaces.PlaceImageRepository
  68. thingTagRepoMock func(mc *minimock.Controller) interfaces.ThingTagRepository
  69. thingNotificationRepoMock func(mc *minimock.Controller) interfaces.ThingNotificationRepository
  70. fileRepoMock func(mc *minimock.Controller) interfaces.FileRepository
  71. }{
  72. {
  73. name: "negative case - bad request",
  74. req: req{
  75. method: fiber.MethodDelete,
  76. route: "/v1/places/" + gofakeit.Word(),
  77. },
  78. resCode: fiber.StatusBadRequest,
  79. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  80. return repoMocks.NewPlaceRepositoryMock(mc)
  81. },
  82. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  83. return repoMocks.NewThingRepositoryMock(mc)
  84. },
  85. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  86. return repoMocks.NewPlaceThingRepositoryMock(mc)
  87. },
  88. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  89. return repoMocks.NewThingImageRepositoryMock(mc)
  90. },
  91. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  92. return repoMocks.NewPlaceImageRepositoryMock(mc)
  93. },
  94. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  95. return repoMocks.NewThingTagRepositoryMock(mc)
  96. },
  97. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  98. return repoMocks.NewThingNotificationRepositoryMock(mc)
  99. },
  100. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  101. return repoMocks.NewFileRepositoryMock(mc)
  102. },
  103. },
  104. {
  105. name: "negative case - bad request (place not found)",
  106. req: correctReq,
  107. resCode: fiber.StatusBadRequest,
  108. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  109. mock := repoMocks.NewPlaceRepositoryMock(mc)
  110. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  111. assert.Equal(mc, placeID, id)
  112. }).Return(nil, sql.ErrNoRows)
  113. return mock
  114. },
  115. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  116. return repoMocks.NewThingRepositoryMock(mc)
  117. },
  118. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  119. return repoMocks.NewPlaceThingRepositoryMock(mc)
  120. },
  121. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  122. return repoMocks.NewThingImageRepositoryMock(mc)
  123. },
  124. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  125. return repoMocks.NewPlaceImageRepositoryMock(mc)
  126. },
  127. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  128. return repoMocks.NewThingTagRepositoryMock(mc)
  129. },
  130. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  131. return repoMocks.NewThingNotificationRepositoryMock(mc)
  132. },
  133. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  134. return repoMocks.NewFileRepositoryMock(mc)
  135. },
  136. },
  137. {
  138. name: "negative case - repository error (get place)",
  139. req: correctReq,
  140. resCode: fiber.StatusInternalServerError,
  141. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  142. mock := repoMocks.NewPlaceRepositoryMock(mc)
  143. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  144. assert.Equal(mc, placeID, id)
  145. }).Return(nil, testError)
  146. return mock
  147. },
  148. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  149. return repoMocks.NewThingRepositoryMock(mc)
  150. },
  151. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  152. return repoMocks.NewPlaceThingRepositoryMock(mc)
  153. },
  154. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  155. return repoMocks.NewThingImageRepositoryMock(mc)
  156. },
  157. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  158. return repoMocks.NewPlaceImageRepositoryMock(mc)
  159. },
  160. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  161. return repoMocks.NewThingTagRepositoryMock(mc)
  162. },
  163. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  164. return repoMocks.NewThingNotificationRepositoryMock(mc)
  165. },
  166. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  167. return repoMocks.NewFileRepositoryMock(mc)
  168. },
  169. },
  170. {
  171. name: "negative case - repository error (get nested places)",
  172. req: correctReq,
  173. resCode: fiber.StatusInternalServerError,
  174. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  175. mock := repoMocks.NewPlaceRepositoryMock(mc)
  176. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  177. assert.Equal(mc, placeID, id)
  178. }).Return(nil, nil)
  179. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  180. assert.Equal(mc, placeID, id)
  181. }).Return(nil, testError)
  182. return mock
  183. },
  184. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  185. return repoMocks.NewThingRepositoryMock(mc)
  186. },
  187. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  188. return repoMocks.NewPlaceThingRepositoryMock(mc)
  189. },
  190. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  191. return repoMocks.NewThingImageRepositoryMock(mc)
  192. },
  193. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  194. return repoMocks.NewPlaceImageRepositoryMock(mc)
  195. },
  196. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  197. return repoMocks.NewThingTagRepositoryMock(mc)
  198. },
  199. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  200. return repoMocks.NewThingNotificationRepositoryMock(mc)
  201. },
  202. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  203. return repoMocks.NewFileRepositoryMock(mc)
  204. },
  205. },
  206. {
  207. name: "negative case - bad request (nested places exists)",
  208. req: correctReq,
  209. resCode: fiber.StatusBadRequest,
  210. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  211. mock := repoMocks.NewPlaceRepositoryMock(mc)
  212. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  213. assert.Equal(mc, placeID, id)
  214. }).Return(nil, nil)
  215. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  216. assert.Equal(mc, placeID, id)
  217. }).Return([]models.Place{{}}, nil)
  218. return mock
  219. },
  220. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  221. return repoMocks.NewThingRepositoryMock(mc)
  222. },
  223. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  224. return repoMocks.NewPlaceThingRepositoryMock(mc)
  225. },
  226. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  227. return repoMocks.NewThingImageRepositoryMock(mc)
  228. },
  229. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  230. return repoMocks.NewPlaceImageRepositoryMock(mc)
  231. },
  232. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  233. return repoMocks.NewThingTagRepositoryMock(mc)
  234. },
  235. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  236. return repoMocks.NewThingNotificationRepositoryMock(mc)
  237. },
  238. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  239. return repoMocks.NewFileRepositoryMock(mc)
  240. },
  241. },
  242. {
  243. name: "negative case - repository error (get place images)",
  244. req: correctReq,
  245. resCode: fiber.StatusInternalServerError,
  246. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  247. mock := repoMocks.NewPlaceRepositoryMock(mc)
  248. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  249. assert.Equal(mc, placeID, id)
  250. }).Return(nil, nil)
  251. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  252. assert.Equal(mc, placeID, id)
  253. }).Return(nil, nil)
  254. return mock
  255. },
  256. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  257. return repoMocks.NewThingRepositoryMock(mc)
  258. },
  259. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  260. return repoMocks.NewPlaceThingRepositoryMock(mc)
  261. },
  262. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  263. return repoMocks.NewThingImageRepositoryMock(mc)
  264. },
  265. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  266. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  267. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  268. assert.Equal(mc, placeID, id)
  269. }).Return(nil, testError)
  270. return mock
  271. },
  272. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  273. return repoMocks.NewThingTagRepositoryMock(mc)
  274. },
  275. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  276. return repoMocks.NewThingNotificationRepositoryMock(mc)
  277. },
  278. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  279. return repoMocks.NewFileRepositoryMock(mc)
  280. },
  281. },
  282. {
  283. name: "negative case - repository error (get things)",
  284. req: correctReq,
  285. resCode: fiber.StatusInternalServerError,
  286. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  287. mock := repoMocks.NewPlaceRepositoryMock(mc)
  288. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  289. assert.Equal(mc, placeID, id)
  290. }).Return(nil, nil)
  291. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  292. assert.Equal(mc, placeID, id)
  293. }).Return(nil, nil)
  294. return mock
  295. },
  296. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  297. mock := repoMocks.NewThingRepositoryMock(mc)
  298. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  299. assert.Equal(mc, placeID, id)
  300. }).Return(nil, testError)
  301. return mock
  302. },
  303. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  304. return repoMocks.NewPlaceThingRepositoryMock(mc)
  305. },
  306. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  307. return repoMocks.NewThingImageRepositoryMock(mc)
  308. },
  309. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  310. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  311. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  312. assert.Equal(mc, placeID, id)
  313. }).Return(nil, nil)
  314. return mock
  315. },
  316. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  317. return repoMocks.NewThingTagRepositoryMock(mc)
  318. },
  319. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  320. return repoMocks.NewThingNotificationRepositoryMock(mc)
  321. },
  322. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  323. return repoMocks.NewFileRepositoryMock(mc)
  324. },
  325. },
  326. {
  327. name: "negative case - repository error (get things images)",
  328. req: correctReq,
  329. resCode: fiber.StatusInternalServerError,
  330. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  331. mock := repoMocks.NewPlaceRepositoryMock(mc)
  332. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  333. assert.Equal(mc, placeID, id)
  334. }).Return(nil, nil)
  335. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  336. assert.Equal(mc, placeID, id)
  337. }).Return(nil, nil)
  338. return mock
  339. },
  340. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  341. mock := repoMocks.NewThingRepositoryMock(mc)
  342. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  343. assert.Equal(mc, placeID, id)
  344. }).Return(thingRepoRes, nil)
  345. return mock
  346. },
  347. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  348. return repoMocks.NewPlaceThingRepositoryMock(mc)
  349. },
  350. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  351. mock := repoMocks.NewThingImageRepositoryMock(mc)
  352. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  353. assert.Equal(mc, thingID, id)
  354. }).Return(nil, testError)
  355. return mock
  356. },
  357. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  358. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  359. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  360. assert.Equal(mc, placeID, id)
  361. }).Return(nil, nil)
  362. return mock
  363. },
  364. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  365. return repoMocks.NewThingTagRepositoryMock(mc)
  366. },
  367. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  368. return repoMocks.NewThingNotificationRepositoryMock(mc)
  369. },
  370. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  371. return repoMocks.NewFileRepositoryMock(mc)
  372. },
  373. },
  374. {
  375. name: "negative case - repository error (begin tx)",
  376. req: correctReq,
  377. resCode: fiber.StatusInternalServerError,
  378. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  379. mock := repoMocks.NewPlaceRepositoryMock(mc)
  380. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  381. assert.Equal(mc, placeID, id)
  382. }).Return(nil, nil)
  383. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  384. assert.Equal(mc, placeID, id)
  385. }).Return(nil, nil)
  386. mock.BeginTxMock.Return(nil, testError)
  387. return mock
  388. },
  389. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  390. mock := repoMocks.NewThingRepositoryMock(mc)
  391. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  392. assert.Equal(mc, placeID, id)
  393. }).Return(thingRepoRes, nil)
  394. return mock
  395. },
  396. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  397. return repoMocks.NewPlaceThingRepositoryMock(mc)
  398. },
  399. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  400. mock := repoMocks.NewThingImageRepositoryMock(mc)
  401. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  402. assert.Equal(mc, thingID, id)
  403. }).Return(thingImageRepoRes, nil)
  404. return mock
  405. },
  406. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  407. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  408. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  409. assert.Equal(mc, placeID, id)
  410. }).Return(nil, nil)
  411. return mock
  412. },
  413. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  414. return repoMocks.NewThingTagRepositoryMock(mc)
  415. },
  416. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  417. return repoMocks.NewThingNotificationRepositoryMock(mc)
  418. },
  419. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  420. return repoMocks.NewFileRepositoryMock(mc)
  421. },
  422. },
  423. {
  424. name: "negative case - repository error (delete place image)",
  425. req: correctReq,
  426. resCode: fiber.StatusInternalServerError,
  427. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  428. mock := repoMocks.NewPlaceRepositoryMock(mc)
  429. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  430. assert.Equal(mc, placeID, id)
  431. }).Return(nil, nil)
  432. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  433. assert.Equal(mc, placeID, id)
  434. }).Return(nil, nil)
  435. mock.BeginTxMock.Return(nil, nil)
  436. return mock
  437. },
  438. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  439. mock := repoMocks.NewThingRepositoryMock(mc)
  440. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  441. assert.Equal(mc, placeID, id)
  442. }).Return(thingRepoRes, nil)
  443. return mock
  444. },
  445. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  446. return repoMocks.NewPlaceThingRepositoryMock(mc)
  447. },
  448. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  449. mock := repoMocks.NewThingImageRepositoryMock(mc)
  450. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  451. assert.Equal(mc, thingID, id)
  452. }).Return(thingImageRepoRes, nil)
  453. return mock
  454. },
  455. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  456. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  457. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  458. assert.Equal(mc, placeID, id)
  459. }).Return(placeImageRepoRes, nil)
  460. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  461. assert.Equal(mc, placeImageID, id)
  462. }).Return(testError)
  463. return mock
  464. },
  465. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  466. return repoMocks.NewThingTagRepositoryMock(mc)
  467. },
  468. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  469. return repoMocks.NewThingNotificationRepositoryMock(mc)
  470. },
  471. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  472. return repoMocks.NewFileRepositoryMock(mc)
  473. },
  474. },
  475. {
  476. name: "negative case - repository error (delete thing image)",
  477. req: correctReq,
  478. resCode: fiber.StatusInternalServerError,
  479. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  480. mock := repoMocks.NewPlaceRepositoryMock(mc)
  481. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  482. assert.Equal(mc, placeID, id)
  483. }).Return(nil, nil)
  484. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  485. assert.Equal(mc, placeID, id)
  486. }).Return(nil, nil)
  487. mock.BeginTxMock.Return(nil, nil)
  488. return mock
  489. },
  490. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  491. mock := repoMocks.NewThingRepositoryMock(mc)
  492. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  493. assert.Equal(mc, placeID, id)
  494. }).Return(thingRepoRes, nil)
  495. return mock
  496. },
  497. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  498. return repoMocks.NewPlaceThingRepositoryMock(mc)
  499. },
  500. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  501. mock := repoMocks.NewThingImageRepositoryMock(mc)
  502. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  503. assert.Equal(mc, thingID, id)
  504. }).Return(thingImageRepoRes, nil)
  505. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  506. assert.Equal(mc, thingImageID, id)
  507. }).Return(testError)
  508. return mock
  509. },
  510. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  511. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  512. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  513. assert.Equal(mc, placeID, id)
  514. }).Return(placeImageRepoRes, nil)
  515. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  516. assert.Equal(mc, placeImageID, id)
  517. }).Return(nil)
  518. return mock
  519. },
  520. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  521. return repoMocks.NewThingTagRepositoryMock(mc)
  522. },
  523. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  524. return repoMocks.NewThingNotificationRepositoryMock(mc)
  525. },
  526. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  527. return repoMocks.NewFileRepositoryMock(mc)
  528. },
  529. },
  530. {
  531. name: "negative case - repository error (delete place thing)",
  532. req: correctReq,
  533. resCode: fiber.StatusInternalServerError,
  534. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  535. mock := repoMocks.NewPlaceRepositoryMock(mc)
  536. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  537. assert.Equal(mc, placeID, id)
  538. }).Return(nil, nil)
  539. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  540. assert.Equal(mc, placeID, id)
  541. }).Return(nil, nil)
  542. mock.BeginTxMock.Return(nil, nil)
  543. return mock
  544. },
  545. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  546. mock := repoMocks.NewThingRepositoryMock(mc)
  547. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  548. assert.Equal(mc, placeID, id)
  549. }).Return(thingRepoRes, nil)
  550. return mock
  551. },
  552. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  553. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  554. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  555. assert.Equal(mc, thingID, id)
  556. }).Return(testError)
  557. return mock
  558. },
  559. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  560. mock := repoMocks.NewThingImageRepositoryMock(mc)
  561. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  562. assert.Equal(mc, thingID, id)
  563. }).Return(thingImageRepoRes, nil)
  564. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  565. assert.Equal(mc, thingImageID, id)
  566. }).Return(nil)
  567. return mock
  568. },
  569. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  570. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  571. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  572. assert.Equal(mc, placeID, id)
  573. }).Return(placeImageRepoRes, nil)
  574. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  575. assert.Equal(mc, placeImageID, id)
  576. }).Return(nil)
  577. return mock
  578. },
  579. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  580. return repoMocks.NewThingTagRepositoryMock(mc)
  581. },
  582. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  583. return repoMocks.NewThingNotificationRepositoryMock(mc)
  584. },
  585. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  586. return repoMocks.NewFileRepositoryMock(mc)
  587. },
  588. },
  589. {
  590. name: "negative case - repository error (delete thing tags)",
  591. req: correctReq,
  592. resCode: fiber.StatusInternalServerError,
  593. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  594. mock := repoMocks.NewPlaceRepositoryMock(mc)
  595. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  596. assert.Equal(mc, placeID, id)
  597. }).Return(nil, nil)
  598. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  599. assert.Equal(mc, placeID, id)
  600. }).Return(nil, nil)
  601. mock.BeginTxMock.Return(nil, nil)
  602. return mock
  603. },
  604. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  605. mock := repoMocks.NewThingRepositoryMock(mc)
  606. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  607. assert.Equal(mc, placeID, id)
  608. }).Return(thingRepoRes, nil)
  609. return mock
  610. },
  611. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  612. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  613. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  614. assert.Equal(mc, thingID, id)
  615. }).Return(nil)
  616. return mock
  617. },
  618. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  619. mock := repoMocks.NewThingImageRepositoryMock(mc)
  620. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  621. assert.Equal(mc, thingID, id)
  622. }).Return(thingImageRepoRes, nil)
  623. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  624. assert.Equal(mc, thingImageID, id)
  625. }).Return(nil)
  626. return mock
  627. },
  628. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  629. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  630. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  631. assert.Equal(mc, placeID, id)
  632. }).Return(placeImageRepoRes, nil)
  633. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  634. assert.Equal(mc, placeImageID, id)
  635. }).Return(nil)
  636. return mock
  637. },
  638. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  639. mock := repoMocks.NewThingTagRepositoryMock(mc)
  640. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  641. assert.Equal(mc, thingID, id)
  642. }).Return(testError)
  643. return mock
  644. },
  645. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  646. return repoMocks.NewThingNotificationRepositoryMock(mc)
  647. },
  648. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  649. return repoMocks.NewFileRepositoryMock(mc)
  650. },
  651. },
  652. {
  653. name: "negative case - repository error (delete thing notifications)",
  654. req: correctReq,
  655. resCode: fiber.StatusInternalServerError,
  656. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  657. mock := repoMocks.NewPlaceRepositoryMock(mc)
  658. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  659. assert.Equal(mc, placeID, id)
  660. }).Return(nil, nil)
  661. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  662. assert.Equal(mc, placeID, id)
  663. }).Return(nil, nil)
  664. mock.BeginTxMock.Return(nil, nil)
  665. return mock
  666. },
  667. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  668. mock := repoMocks.NewThingRepositoryMock(mc)
  669. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  670. assert.Equal(mc, placeID, id)
  671. }).Return(thingRepoRes, nil)
  672. return mock
  673. },
  674. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  675. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  676. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  677. assert.Equal(mc, thingID, id)
  678. }).Return(nil)
  679. return mock
  680. },
  681. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  682. mock := repoMocks.NewThingImageRepositoryMock(mc)
  683. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  684. assert.Equal(mc, thingID, id)
  685. }).Return(thingImageRepoRes, nil)
  686. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  687. assert.Equal(mc, thingImageID, id)
  688. }).Return(nil)
  689. return mock
  690. },
  691. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  692. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  693. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  694. assert.Equal(mc, placeID, id)
  695. }).Return(placeImageRepoRes, nil)
  696. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  697. assert.Equal(mc, placeImageID, id)
  698. }).Return(nil)
  699. return mock
  700. },
  701. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  702. mock := repoMocks.NewThingTagRepositoryMock(mc)
  703. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  704. assert.Equal(mc, thingID, id)
  705. }).Return(nil)
  706. return mock
  707. },
  708. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  709. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  710. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  711. assert.Equal(mc, thingID, id)
  712. }).Return(testError)
  713. return mock
  714. },
  715. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  716. return repoMocks.NewFileRepositoryMock(mc)
  717. },
  718. },
  719. {
  720. name: "negative case - repository error (delete thing)",
  721. req: correctReq,
  722. resCode: fiber.StatusInternalServerError,
  723. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  724. mock := repoMocks.NewPlaceRepositoryMock(mc)
  725. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  726. assert.Equal(mc, placeID, id)
  727. }).Return(nil, nil)
  728. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  729. assert.Equal(mc, placeID, id)
  730. }).Return(nil, nil)
  731. mock.BeginTxMock.Return(nil, nil)
  732. return mock
  733. },
  734. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  735. mock := repoMocks.NewThingRepositoryMock(mc)
  736. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  737. assert.Equal(mc, placeID, id)
  738. }).Return(thingRepoRes, nil)
  739. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  740. assert.Equal(mc, thingID, id)
  741. }).Return(testError)
  742. return mock
  743. },
  744. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  745. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  746. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  747. assert.Equal(mc, thingID, id)
  748. }).Return(nil)
  749. return mock
  750. },
  751. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  752. mock := repoMocks.NewThingImageRepositoryMock(mc)
  753. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  754. assert.Equal(mc, thingID, id)
  755. }).Return(thingImageRepoRes, nil)
  756. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  757. assert.Equal(mc, thingImageID, id)
  758. }).Return(nil)
  759. return mock
  760. },
  761. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  762. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  763. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  764. assert.Equal(mc, placeID, id)
  765. }).Return(placeImageRepoRes, nil)
  766. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  767. assert.Equal(mc, placeImageID, id)
  768. }).Return(nil)
  769. return mock
  770. },
  771. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  772. mock := repoMocks.NewThingTagRepositoryMock(mc)
  773. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  774. assert.Equal(mc, thingID, id)
  775. }).Return(nil)
  776. return mock
  777. },
  778. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  779. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  780. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  781. assert.Equal(mc, thingID, id)
  782. }).Return(nil)
  783. return mock
  784. },
  785. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  786. return repoMocks.NewFileRepositoryMock(mc)
  787. },
  788. },
  789. {
  790. name: "negative case - repository error (delete place)",
  791. req: correctReq,
  792. resCode: fiber.StatusInternalServerError,
  793. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  794. mock := repoMocks.NewPlaceRepositoryMock(mc)
  795. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  796. assert.Equal(mc, placeID, id)
  797. }).Return(nil, nil)
  798. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  799. assert.Equal(mc, placeID, id)
  800. }).Return(nil, nil)
  801. mock.BeginTxMock.Return(nil, nil)
  802. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  803. assert.Equal(mc, placeID, id)
  804. }).Return(testError)
  805. return mock
  806. },
  807. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  808. mock := repoMocks.NewThingRepositoryMock(mc)
  809. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  810. assert.Equal(mc, placeID, id)
  811. }).Return(thingRepoRes, nil)
  812. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  813. assert.Equal(mc, thingID, id)
  814. }).Return(nil)
  815. return mock
  816. },
  817. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  818. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  819. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  820. assert.Equal(mc, thingID, id)
  821. }).Return(nil)
  822. return mock
  823. },
  824. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  825. mock := repoMocks.NewThingImageRepositoryMock(mc)
  826. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  827. assert.Equal(mc, thingID, id)
  828. }).Return(thingImageRepoRes, nil)
  829. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  830. assert.Equal(mc, thingImageID, id)
  831. }).Return(nil)
  832. return mock
  833. },
  834. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  835. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  836. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  837. assert.Equal(mc, placeID, id)
  838. }).Return(placeImageRepoRes, nil)
  839. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  840. assert.Equal(mc, placeImageID, id)
  841. }).Return(nil)
  842. return mock
  843. },
  844. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  845. mock := repoMocks.NewThingTagRepositoryMock(mc)
  846. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  847. assert.Equal(mc, thingID, id)
  848. }).Return(nil)
  849. return mock
  850. },
  851. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  852. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  853. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  854. assert.Equal(mc, thingID, id)
  855. }).Return(nil)
  856. return mock
  857. },
  858. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  859. return repoMocks.NewFileRepositoryMock(mc)
  860. },
  861. },
  862. {
  863. name: "negative case - repository error (commit tx)",
  864. req: correctReq,
  865. resCode: fiber.StatusInternalServerError,
  866. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  867. mock := repoMocks.NewPlaceRepositoryMock(mc)
  868. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  869. assert.Equal(mc, placeID, id)
  870. }).Return(nil, nil)
  871. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  872. assert.Equal(mc, placeID, id)
  873. }).Return(nil, nil)
  874. mock.BeginTxMock.Return(nil, nil)
  875. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  876. assert.Equal(mc, placeID, id)
  877. }).Return(nil)
  878. mock.CommitTxMock.Return(testError)
  879. return mock
  880. },
  881. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  882. mock := repoMocks.NewThingRepositoryMock(mc)
  883. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  884. assert.Equal(mc, placeID, id)
  885. }).Return(thingRepoRes, nil)
  886. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  887. assert.Equal(mc, thingID, id)
  888. }).Return(nil)
  889. return mock
  890. },
  891. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  892. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  893. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  894. assert.Equal(mc, thingID, id)
  895. }).Return(nil)
  896. return mock
  897. },
  898. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  899. mock := repoMocks.NewThingImageRepositoryMock(mc)
  900. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  901. assert.Equal(mc, thingID, id)
  902. }).Return(thingImageRepoRes, nil)
  903. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  904. assert.Equal(mc, thingImageID, id)
  905. }).Return(nil)
  906. return mock
  907. },
  908. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  909. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  910. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  911. assert.Equal(mc, placeID, id)
  912. }).Return(placeImageRepoRes, nil)
  913. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  914. assert.Equal(mc, placeImageID, id)
  915. }).Return(nil)
  916. return mock
  917. },
  918. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  919. mock := repoMocks.NewThingTagRepositoryMock(mc)
  920. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  921. assert.Equal(mc, thingID, id)
  922. }).Return(nil)
  923. return mock
  924. },
  925. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  926. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  927. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  928. assert.Equal(mc, thingID, id)
  929. }).Return(nil)
  930. return mock
  931. },
  932. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  933. return repoMocks.NewFileRepositoryMock(mc)
  934. },
  935. },
  936. {
  937. name: "negative case - delete place image error",
  938. req: correctReq,
  939. resCode: fiber.StatusInternalServerError,
  940. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  941. mock := repoMocks.NewPlaceRepositoryMock(mc)
  942. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  943. assert.Equal(mc, placeID, id)
  944. }).Return(nil, nil)
  945. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  946. assert.Equal(mc, placeID, id)
  947. }).Return(nil, nil)
  948. mock.BeginTxMock.Return(nil, nil)
  949. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  950. assert.Equal(mc, placeID, id)
  951. }).Return(nil)
  952. mock.CommitTxMock.Return(nil)
  953. return mock
  954. },
  955. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  956. mock := repoMocks.NewThingRepositoryMock(mc)
  957. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  958. assert.Equal(mc, placeID, id)
  959. }).Return(thingRepoRes, nil)
  960. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  961. assert.Equal(mc, thingID, id)
  962. }).Return(nil)
  963. return mock
  964. },
  965. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  966. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  967. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  968. assert.Equal(mc, thingID, id)
  969. }).Return(nil)
  970. return mock
  971. },
  972. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  973. mock := repoMocks.NewThingImageRepositoryMock(mc)
  974. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  975. assert.Equal(mc, thingID, id)
  976. }).Return(thingImageRepoRes, nil)
  977. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  978. assert.Equal(mc, thingImageID, id)
  979. }).Return(nil)
  980. return mock
  981. },
  982. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  983. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  984. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  985. assert.Equal(mc, placeID, id)
  986. }).Return(placeImageRepoRes, nil)
  987. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  988. assert.Equal(mc, placeImageID, id)
  989. }).Return(nil)
  990. return mock
  991. },
  992. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  993. mock := repoMocks.NewThingTagRepositoryMock(mc)
  994. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  995. assert.Equal(mc, thingID, id)
  996. }).Return(nil)
  997. return mock
  998. },
  999. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  1000. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  1001. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1002. assert.Equal(mc, thingID, id)
  1003. }).Return(nil)
  1004. return mock
  1005. },
  1006. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  1007. mock := repoMocks.NewFileRepositoryMock(mc)
  1008. mock.DeleteMock.When(placeImageURL).Then(testError)
  1009. return mock
  1010. },
  1011. },
  1012. {
  1013. name: "negative case - delete thing image error",
  1014. req: correctReq,
  1015. resCode: fiber.StatusInternalServerError,
  1016. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  1017. mock := repoMocks.NewPlaceRepositoryMock(mc)
  1018. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  1019. assert.Equal(mc, placeID, id)
  1020. }).Return(nil, nil)
  1021. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  1022. assert.Equal(mc, placeID, id)
  1023. }).Return(nil, nil)
  1024. mock.BeginTxMock.Return(nil, nil)
  1025. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1026. assert.Equal(mc, placeID, id)
  1027. }).Return(nil)
  1028. mock.CommitTxMock.Return(nil)
  1029. return mock
  1030. },
  1031. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  1032. mock := repoMocks.NewThingRepositoryMock(mc)
  1033. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  1034. assert.Equal(mc, placeID, id)
  1035. }).Return(thingRepoRes, nil)
  1036. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1037. assert.Equal(mc, thingID, id)
  1038. }).Return(nil)
  1039. return mock
  1040. },
  1041. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  1042. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  1043. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1044. assert.Equal(mc, thingID, id)
  1045. }).Return(nil)
  1046. return mock
  1047. },
  1048. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  1049. mock := repoMocks.NewThingImageRepositoryMock(mc)
  1050. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  1051. assert.Equal(mc, thingID, id)
  1052. }).Return(thingImageRepoRes, nil)
  1053. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1054. assert.Equal(mc, thingImageID, id)
  1055. }).Return(nil)
  1056. return mock
  1057. },
  1058. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  1059. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  1060. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  1061. assert.Equal(mc, placeID, id)
  1062. }).Return(placeImageRepoRes, nil)
  1063. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1064. assert.Equal(mc, placeImageID, id)
  1065. }).Return(nil)
  1066. return mock
  1067. },
  1068. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  1069. mock := repoMocks.NewThingTagRepositoryMock(mc)
  1070. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1071. assert.Equal(mc, thingID, id)
  1072. }).Return(nil)
  1073. return mock
  1074. },
  1075. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  1076. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  1077. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1078. assert.Equal(mc, thingID, id)
  1079. }).Return(nil)
  1080. return mock
  1081. },
  1082. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  1083. mock := repoMocks.NewFileRepositoryMock(mc)
  1084. mock.DeleteMock.When(placeImageURL).Then(nil)
  1085. mock.DeleteMock.When(thingImageURL).Then(testError)
  1086. return mock
  1087. },
  1088. },
  1089. {
  1090. name: "positive case",
  1091. req: correctReq,
  1092. resCode: fiber.StatusOK,
  1093. resBody: &dto.EmptyResponse{},
  1094. placeRepoMock: func(mc *minimock.Controller) interfaces.PlaceRepository {
  1095. mock := repoMocks.NewPlaceRepositoryMock(mc)
  1096. mock.GetMock.Inspect(func(ctx context.Context, id int) {
  1097. assert.Equal(mc, placeID, id)
  1098. }).Return(nil, nil)
  1099. mock.GetNestedPlacesMock.Inspect(func(ctx context.Context, id int) {
  1100. assert.Equal(mc, placeID, id)
  1101. }).Return(nil, nil)
  1102. mock.BeginTxMock.Return(nil, nil)
  1103. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1104. assert.Equal(mc, placeID, id)
  1105. }).Return(nil)
  1106. mock.CommitTxMock.Return(nil)
  1107. return mock
  1108. },
  1109. thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
  1110. mock := repoMocks.NewThingRepositoryMock(mc)
  1111. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  1112. assert.Equal(mc, placeID, id)
  1113. }).Return(thingRepoRes, nil)
  1114. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1115. assert.Equal(mc, thingID, id)
  1116. }).Return(nil)
  1117. return mock
  1118. },
  1119. placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
  1120. mock := repoMocks.NewPlaceThingRepositoryMock(mc)
  1121. mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1122. assert.Equal(mc, thingID, id)
  1123. }).Return(nil)
  1124. return mock
  1125. },
  1126. thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
  1127. mock := repoMocks.NewThingImageRepositoryMock(mc)
  1128. mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
  1129. assert.Equal(mc, thingID, id)
  1130. }).Return(thingImageRepoRes, nil)
  1131. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1132. assert.Equal(mc, thingImageID, id)
  1133. }).Return(nil)
  1134. return mock
  1135. },
  1136. placeImageRepoMock: func(mc *minimock.Controller) interfaces.PlaceImageRepository {
  1137. mock := repoMocks.NewPlaceImageRepositoryMock(mc)
  1138. mock.GetByPlaceIDMock.Inspect(func(ctx context.Context, id int) {
  1139. assert.Equal(mc, placeID, id)
  1140. }).Return(placeImageRepoRes, nil)
  1141. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1142. assert.Equal(mc, placeImageID, id)
  1143. }).Return(nil)
  1144. return mock
  1145. },
  1146. thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
  1147. mock := repoMocks.NewThingTagRepositoryMock(mc)
  1148. mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1149. assert.Equal(mc, thingID, id)
  1150. }).Return(nil)
  1151. return mock
  1152. },
  1153. thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
  1154. mock := repoMocks.NewThingNotificationRepositoryMock(mc)
  1155. mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
  1156. assert.Equal(mc, thingID, id)
  1157. }).Return(nil)
  1158. return mock
  1159. },
  1160. fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
  1161. mock := repoMocks.NewFileRepositoryMock(mc)
  1162. mock.DeleteMock.When(placeImageURL).Then(nil)
  1163. mock.DeleteMock.When(thingImageURL).Then(nil)
  1164. return mock
  1165. },
  1166. },
  1167. }
  1168. for _, tt := range tests {
  1169. t.Run(tt.name, func(t *testing.T) {
  1170. fiberApp := fiber.New()
  1171. serviceProvider := sp.InitMock(
  1172. tt.placeRepoMock(mc),
  1173. tt.thingRepoMock(mc),
  1174. tt.placeThingRepoMock(mc),
  1175. tt.placeImageRepoMock(mc),
  1176. tt.thingImageRepoMock(mc),
  1177. tt.thingTagRepoMock(mc),
  1178. tt.thingNotificationRepoMock(mc),
  1179. tt.fileRepoMock(mc),
  1180. )
  1181. fiberApp.Delete("/v1/places/:placeId", DeletePlaceHandler(serviceProvider))
  1182. fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
  1183. assert.Equal(t, tt.resCode, fiberRes.StatusCode)
  1184. if tt.resBody != nil {
  1185. assert.Equal(t, helpers.MarshalResponse(tt.resBody), helpers.ConvertBodyToString(fiberRes.Body))
  1186. }
  1187. })
  1188. }
  1189. }