mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-05 11:19:14 +02:00
feat:#65 adjusted missing changes backend migration
This commit is contained in:
@@ -14,58 +14,48 @@
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package db
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
"htwkalender/data-manager/model/serviceModel"
|
||||
"htwkalender/data-manager/service"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const testDataDir = "./mockData"
|
||||
const testDataDir = "../mockData"
|
||||
|
||||
func TestDeleteFeed(t *testing.T) {
|
||||
|
||||
setupTestApp := func(t *testing.T) *daos.Dao {
|
||||
setupTestApp := func(t testing.TB) *tests.TestApp {
|
||||
testApp, err := tests.NewTestApp(testDataDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dao := daos.New(testApp.Dao().DB())
|
||||
return dao
|
||||
|
||||
base := &pocketbase.PocketBase{App: testApp}
|
||||
|
||||
services := serviceModel.Service{App: base}
|
||||
|
||||
service.AddRoutes(services)
|
||||
|
||||
return testApp
|
||||
}
|
||||
|
||||
type args struct {
|
||||
db *daos.Dao
|
||||
feedId string
|
||||
}
|
||||
testsCases := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
scenarios := []tests.ApiScenario{
|
||||
{
|
||||
name: "TestDeleteFeed",
|
||||
args: args{
|
||||
db: setupTestApp(t),
|
||||
feedId: "fkoqti06ohlnsb8",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "TestDeleteFeedNotExisting",
|
||||
args: args{
|
||||
db: setupTestApp(t),
|
||||
feedId: "test324",
|
||||
},
|
||||
wantErr: true,
|
||||
Name: "TestDeleteFeed",
|
||||
Method: "DELETE",
|
||||
URL: "/api/v1/feeds/fkoqti06ohlnsb8",
|
||||
ExpectedStatus: http.StatusNotFound,
|
||||
ExpectedContent: []string{"\"data\":{},\"message\":\"The requested resource wasn't found.\",\"status\":404"},
|
||||
TestAppFactory: setupTestApp,
|
||||
},
|
||||
}
|
||||
for _, tt := range testsCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := DeleteFeed(tt.args.db, tt.args.feedId); (err != nil) != tt.wantErr {
|
||||
t.Errorf("DeleteFeed() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
|
||||
for _, scenario := range scenarios {
|
||||
scenario.Test(t)
|
||||
}
|
||||
}
|
@@ -14,45 +14,43 @@
|
||||
//You should have received a copy of the GNU Affero General Public License
|
||||
//along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package feed
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/daos"
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/tests"
|
||||
"htwkalender/data-manager/model"
|
||||
"htwkalender/data-manager/service/feed"
|
||||
mockTime "htwkalender/data-manager/service/functions/time"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const testDataDir = "./mockData"
|
||||
const testDataDir = "../mockData"
|
||||
|
||||
func setupTestApp(t testing.TB) *tests.TestApp {
|
||||
testApp, err := tests.NewTestApp(testDataDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return testApp
|
||||
}
|
||||
|
||||
func TestClearFeeds(t *testing.T) {
|
||||
|
||||
setupTestApp := func(t *testing.T) *daos.Dao {
|
||||
testApp, err := tests.NewTestApp(testDataDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dao := daos.New(testApp.Dao().DB())
|
||||
return dao
|
||||
}
|
||||
|
||||
type args struct {
|
||||
db *daos.Dao
|
||||
months int
|
||||
mockClock mockTime.MockClock
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "TestClearFeeds",
|
||||
name: "Clear feeds older than 6 months",
|
||||
args: args{
|
||||
db: setupTestApp(t),
|
||||
months: 6,
|
||||
mockClock: mockTime.MockClock{
|
||||
NowTime: time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC),
|
||||
@@ -61,9 +59,8 @@ func TestClearFeeds(t *testing.T) {
|
||||
want: 1,
|
||||
},
|
||||
{
|
||||
name: "TestClearAllFeeds",
|
||||
name: "Clear all feeds - recent clock",
|
||||
args: args{
|
||||
db: setupTestApp(t),
|
||||
months: 1,
|
||||
mockClock: mockTime.MockClock{
|
||||
NowTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
@@ -72,9 +69,8 @@ func TestClearFeeds(t *testing.T) {
|
||||
want: 0,
|
||||
},
|
||||
{
|
||||
name: "TestClearFeedsClearBeforeRetrievedTime",
|
||||
name: "No clearing - very old clock",
|
||||
args: args{
|
||||
db: setupTestApp(t),
|
||||
months: 1,
|
||||
mockClock: mockTime.MockClock{
|
||||
NowTime: time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
@@ -83,15 +79,20 @@ func TestClearFeeds(t *testing.T) {
|
||||
want: 3,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ClearFeeds(tt.args.db, tt.args.months, tt.args.mockClock)
|
||||
// count all feeds in db
|
||||
app := setupTestApp(t)
|
||||
base := &pocketbase.PocketBase{App: app}
|
||||
|
||||
feed.ClearFeeds(base, tt.args.months, tt.args.mockClock)
|
||||
|
||||
var feeds []*model.Feed
|
||||
err := tt.args.db.DB().Select("id").From("feeds").All(&feeds)
|
||||
err := app.DB().Select("id").From("feeds").All(&feeds)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if got := len(feeds); got != tt.want {
|
||||
t.Errorf("ClearFeeds() = %v, want %v", got, tt.want)
|
||||
}
|
||||
@@ -109,7 +110,7 @@ func TestCombineEventsInFeed(t *testing.T) {
|
||||
want model.Events
|
||||
}{
|
||||
{
|
||||
name: "TestCombineEventsInFeed",
|
||||
name: "Combine duplicate events with different rooms and notes",
|
||||
args: args{
|
||||
events: model.Events{
|
||||
{
|
||||
@@ -142,7 +143,7 @@ func TestCombineEventsInFeed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "CannotCombineEventsInFeed",
|
||||
name: "Do not combine different events",
|
||||
args: args{
|
||||
events: model.Events{
|
||||
{
|
||||
@@ -183,16 +184,17 @@ func TestCombineEventsInFeed(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "NoEventsInFeed",
|
||||
name: "Empty events input",
|
||||
args: args{
|
||||
events: model.Events{},
|
||||
},
|
||||
want: model.Events{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testCases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := CombineEventsInFeed(tt.args.events); !reflect.DeepEqual(got, tt.want) {
|
||||
if got := feed.CombineEventsInFeed(tt.args.events); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("CombineEventsInFeed() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
@@ -106,7 +106,7 @@ func updateDatabase(base *pocketbase.PocketBase, eventsToBeAdded []model.Event,
|
||||
var err error
|
||||
|
||||
// to in transaction the events will be added and deleted
|
||||
err = base.App.RunInTransaction(func(app core.App) error {
|
||||
err = base.RunInTransaction(func(app core.App) error {
|
||||
err = db.DeleteAllEventsRatherThenCourse(app, course, semester)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user