|
@@ -8,27 +8,27 @@ import (
|
|
"strconv"
|
|
"strconv"
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
- API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
|
|
|
|
- "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
|
|
|
|
- "git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
|
|
|
|
- "git.dmitriygnatenko.ru/dima/homethings/internal/interfaces"
|
|
|
|
- "git.dmitriygnatenko.ru/dima/homethings/internal/models"
|
|
|
|
- repoMocks "git.dmitriygnatenko.ru/dima/homethings/internal/repositories/mocks"
|
|
|
|
- sp "git.dmitriygnatenko.ru/dima/homethings/internal/service_provider"
|
|
|
|
"github.com/brianvoe/gofakeit/v6"
|
|
"github.com/brianvoe/gofakeit/v6"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gojuno/minimock/v3"
|
|
"github.com/gojuno/minimock/v3"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
+
|
|
|
|
+ API "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1"
|
|
|
|
+ "git.dmitriygnatenko.ru/dima/homethings/internal/api/v1/thing/mocks"
|
|
|
|
+ "git.dmitriygnatenko.ru/dima/homethings/internal/dto"
|
|
|
|
+ "git.dmitriygnatenko.ru/dima/homethings/internal/helpers"
|
|
|
|
+ "git.dmitriygnatenko.ru/dima/homethings/internal/models"
|
|
)
|
|
)
|
|
|
|
|
|
-func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
+func TestDeleteThingHandler(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
|
|
+
|
|
type req struct {
|
|
type req struct {
|
|
method string
|
|
method string
|
|
route string
|
|
route string
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
- mc = minimock.NewController(t)
|
|
|
|
thingID = gofakeit.Number(1, 1000)
|
|
thingID = gofakeit.Number(1, 1000)
|
|
imageID = gofakeit.Number(1, 1000)
|
|
imageID = gofakeit.Number(1, 1000)
|
|
imageURL = gofakeit.URL()
|
|
imageURL = gofakeit.URL()
|
|
@@ -52,12 +52,12 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
req req
|
|
req req
|
|
resCode int
|
|
resCode int
|
|
resBody interface{}
|
|
resBody interface{}
|
|
- thingRepoMock func(mc *minimock.Controller) interfaces.ThingRepository
|
|
|
|
- placeThingRepoMock func(mc *minimock.Controller) interfaces.PlaceThingRepository
|
|
|
|
- thingImageRepoMock func(mc *minimock.Controller) interfaces.ThingImageRepository
|
|
|
|
- thingTagRepoMock func(mc *minimock.Controller) interfaces.ThingTagRepository
|
|
|
|
- thingNotificationRepoMock func(mc *minimock.Controller) interfaces.ThingNotificationRepository
|
|
|
|
- fileRepoMock func(mc *minimock.Controller) interfaces.FileRepository
|
|
|
|
|
|
+ thingRepoMock func(mc *minimock.Controller) ThingRepository
|
|
|
|
+ placeThingRepoMock func(mc *minimock.Controller) PlaceThingRepository
|
|
|
|
+ thingImageRepoMock func(mc *minimock.Controller) ThingImageRepository
|
|
|
|
+ thingTagRepoMock func(mc *minimock.Controller) ThingTagRepository
|
|
|
|
+ thingNotificationRepoMock func(mc *minimock.Controller) ThingNotificationRepository
|
|
|
|
+ fileRepoMock func(mc *minimock.Controller) FileRepository
|
|
}{
|
|
}{
|
|
{
|
|
{
|
|
name: "negative case - bad request",
|
|
name: "negative case - bad request",
|
|
@@ -66,31 +66,31 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
route: "/v1/things/" + gofakeit.Word(),
|
|
route: "/v1/things/" + gofakeit.Word(),
|
|
},
|
|
},
|
|
resCode: fiber.StatusBadRequest,
|
|
resCode: fiber.StatusBadRequest,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- return repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ return mocks.NewThingRepositoryMock(mc)
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- return repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ return mocks.NewPlaceThingRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- return repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ return mocks.NewThingImageRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - bad request (thing not found)",
|
|
name: "negative case - bad request (thing not found)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusBadRequest,
|
|
resCode: fiber.StatusBadRequest,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -98,28 +98,28 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- return repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ return mocks.NewPlaceThingRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- return repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ return mocks.NewThingImageRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (get thing)",
|
|
name: "negative case - repository error (get thing)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -127,28 +127,28 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- return repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ return mocks.NewPlaceThingRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- return repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ return mocks.NewThingImageRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (begin tx)",
|
|
name: "negative case - repository error (begin tx)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -158,28 +158,28 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- return repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ return mocks.NewPlaceThingRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- return repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ return mocks.NewThingImageRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (delete place thing)",
|
|
name: "negative case - repository error (delete place thing)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -189,8 +189,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -198,25 +198,25 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- return repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ return mocks.NewThingImageRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (get images)",
|
|
name: "negative case - repository error (get images)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -226,8 +226,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -235,8 +235,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -244,22 +244,22 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (delete images)",
|
|
name: "negative case - repository error (delete images)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -269,8 +269,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -278,8 +278,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -291,22 +291,22 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- return repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ return mocks.NewThingTagRepositoryMock(mc)
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (delete thing tags)",
|
|
name: "negative case - repository error (delete thing tags)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -316,8 +316,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -325,8 +325,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -338,8 +338,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -347,19 +347,19 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- return repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ return mocks.NewThingNotificationRepositoryMock(mc)
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (delete notification)",
|
|
name: "negative case - repository error (delete notification)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -369,8 +369,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -378,8 +378,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -391,8 +391,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -400,8 +400,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- mock := repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ mock := mocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -409,16 +409,16 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (delete thing)",
|
|
name: "negative case - repository error (delete thing)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -432,8 +432,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -441,8 +441,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -454,8 +454,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -463,8 +463,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- mock := repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ mock := mocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -472,16 +472,16 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - repository error (commit tx)",
|
|
name: "negative case - repository error (commit tx)",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -497,8 +497,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -506,8 +506,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -519,8 +519,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -528,8 +528,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- mock := repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ mock := mocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -537,16 +537,16 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- return repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ return mocks.NewFileRepositoryMock(mc)
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
name: "negative case - file delete error",
|
|
name: "negative case - file delete error",
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusInternalServerError,
|
|
resCode: fiber.StatusInternalServerError,
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -562,8 +562,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -571,8 +571,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -584,8 +584,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -593,8 +593,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- mock := repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ mock := mocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -602,8 +602,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- mock := repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ mock := mocks.NewFileRepositoryMock(mc)
|
|
mock.DeleteMock.Return(testError)
|
|
mock.DeleteMock.Return(testError)
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
@@ -613,8 +613,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
req: correctReq,
|
|
req: correctReq,
|
|
resCode: fiber.StatusOK,
|
|
resCode: fiber.StatusOK,
|
|
resBody: dto.EmptyResponse{},
|
|
resBody: dto.EmptyResponse{},
|
|
- thingRepoMock: func(mc *minimock.Controller) interfaces.ThingRepository {
|
|
|
|
- mock := repoMocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
+ thingRepoMock: func(mc *minimock.Controller) ThingRepository {
|
|
|
|
+ mock := mocks.NewThingRepositoryMock(mc)
|
|
|
|
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -630,8 +630,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- placeThingRepoMock: func(mc *minimock.Controller) interfaces.PlaceThingRepository {
|
|
|
|
- mock := repoMocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
+ placeThingRepoMock: func(mc *minimock.Controller) PlaceThingRepository {
|
|
|
|
+ mock := mocks.NewPlaceThingRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteThingMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -639,8 +639,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingImageRepoMock: func(mc *minimock.Controller) interfaces.ThingImageRepository {
|
|
|
|
- mock := repoMocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
+ thingImageRepoMock: func(mc *minimock.Controller) ThingImageRepository {
|
|
|
|
+ mock := mocks.NewThingImageRepositoryMock(mc)
|
|
|
|
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
mock.GetByThingIDMock.Inspect(func(ctx context.Context, id int) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -652,8 +652,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingTagRepoMock: func(mc *minimock.Controller) interfaces.ThingTagRepository {
|
|
|
|
- mock := repoMocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
+ thingTagRepoMock: func(mc *minimock.Controller) ThingTagRepository {
|
|
|
|
+ mock := mocks.NewThingTagRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteByThingIDMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -661,8 +661,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- thingNotificationRepoMock: func(mc *minimock.Controller) interfaces.ThingNotificationRepository {
|
|
|
|
- mock := repoMocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
+ thingNotificationRepoMock: func(mc *minimock.Controller) ThingNotificationRepository {
|
|
|
|
+ mock := mocks.NewThingNotificationRepositoryMock(mc)
|
|
|
|
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
mock.DeleteMock.Inspect(func(ctx context.Context, id int, tx *sql.Tx) {
|
|
assert.Equal(mc, thingID, id)
|
|
assert.Equal(mc, thingID, id)
|
|
@@ -670,8 +670,8 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
- fileRepoMock: func(mc *minimock.Controller) interfaces.FileRepository {
|
|
|
|
- mock := repoMocks.NewFileRepositoryMock(mc)
|
|
|
|
|
|
+ fileRepoMock: func(mc *minimock.Controller) FileRepository {
|
|
|
|
+ mock := mocks.NewFileRepositoryMock(mc)
|
|
mock.DeleteMock.Return(nil)
|
|
mock.DeleteMock.Return(nil)
|
|
return mock
|
|
return mock
|
|
},
|
|
},
|
|
@@ -680,17 +680,19 @@ func Test_DeleteThingHandler(t *testing.T) {
|
|
|
|
|
|
for _, tt := range tests {
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
+ t.Parallel()
|
|
|
|
+
|
|
|
|
+ mc := minimock.NewController(t)
|
|
fiberApp := fiber.New()
|
|
fiberApp := fiber.New()
|
|
- serviceProvider := sp.InitMock(
|
|
|
|
|
|
+
|
|
|
|
+ fiberApp.Delete("/v1/things/:thingId", DeleteThingHandler(
|
|
tt.thingRepoMock(mc),
|
|
tt.thingRepoMock(mc),
|
|
|
|
+ tt.thingTagRepoMock(mc),
|
|
tt.placeThingRepoMock(mc),
|
|
tt.placeThingRepoMock(mc),
|
|
tt.thingImageRepoMock(mc),
|
|
tt.thingImageRepoMock(mc),
|
|
- tt.thingTagRepoMock(mc),
|
|
|
|
tt.thingNotificationRepoMock(mc),
|
|
tt.thingNotificationRepoMock(mc),
|
|
tt.fileRepoMock(mc),
|
|
tt.fileRepoMock(mc),
|
|
- )
|
|
|
|
-
|
|
|
|
- fiberApp.Delete("/v1/things/:thingId", DeleteThingHandler(serviceProvider))
|
|
|
|
|
|
+ ))
|
|
|
|
|
|
fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
|
|
fiberRes, _ := fiberApp.Test(httptest.NewRequest(tt.req.method, tt.req.route, nil), API.DefaultTestTimeOut)
|
|
assert.Equal(t, tt.resCode, fiberRes.StatusCode)
|
|
assert.Equal(t, tt.resCode, fiberRes.StatusCode)
|