delete_place_test.go 43 KB

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