WIP: added test that existing entries should be updated

This commit is contained in:
Philipp Häfelfinger 2019-04-04 09:14:23 +02:00
parent 550230195a
commit 0d7ca76b98

View File

@ -23,7 +23,7 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) {
dbCategories := createDbCategoriesFrom(piwigoCategories)
dbmock := NewMockCategoryProvider(mockCtrl)
dbmock.EXPECT().GetCategoryByPiwigoId(gomock.Any()).Return(datastore.CategoryData{}, datastore.ErrorRecordNotFound).Times(len(piwigoCategories))
for _, cat := range dbCategories {
dbmock.EXPECT().SaveCategory(cat).Times(1)
}
@ -37,6 +37,43 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) {
}
}
func Test_SynchronizePiwigoCategories_updates_a_category(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
piwigoCategories := createTwoServerCategories()
oldCategory := datastore.CategoryData{
PiwigoId: 1,
PiwigoParentId: 0,
CategoryId: 1,
Key: "oldKey",
Name: "oldName",
}
expectedCategory := datastore.CategoryData{
PiwigoId: 1,
PiwigoParentId: 0,
CategoryId: 1,
Name: "2019",
Key: "2019",
}
dbmock := NewMockCategoryProvider(mockCtrl)
dbmock.EXPECT().GetCategoryByPiwigoId(1).Return(oldCategory, nil).Times(1)
dbmock.EXPECT().GetCategoryByPiwigoId(gomock.Any()).Return(datastore.CategoryData{}, datastore.ErrorRecordNotFound).Times(1)
dbmock.EXPECT().SaveCategory(expectedCategory).Times(1)
dbmock.EXPECT().SaveCategory(gomock.Any()).Times(1)
piwigoMock := NewMockPiwigoCategoryApi(mockCtrl)
piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(1)
err := SynchronizePiwigoCategories(piwigoMock, dbmock)
if err != nil {
t.Error(err)
}
}
func createDbCategoriesFrom(categories map[string]*piwigo.PiwigoCategory) []datastore.CategoryData {
dbCategories := []datastore.CategoryData{}
for _, cat := range categories {