//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Affero General Public License for more details.

//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

import (
	"github.com/pocketbase/dbx"
	"reflect"
	"testing"
)

func TestBuildIcalQueryForModules(t *testing.T) {
	type args struct {
		modules []string
	}
	tests := []struct {
		name string
		args args
		want dbx.Expression
	}{
		{
			name: "empty modules",
			args: args{modules: []string{}},
			want: dbx.HashExp{},
		},
		{
			name: "one module",
			args: args{modules: []string{"77eddc32-c49d-5d0a-8c36-17b266396641"}},
			want: dbx.HashExp{"uuid": "77eddc32-c49d-5d0a-8c36-17b266396641"},
		},
		{
			name: "two modules",
			args: args{modules: []string{"9e5081e6-4c56-57b9-9965-f6dc74559755", "48cd8c4e-fb70-595c-9dfb-7035f56326d9"}},
			want: dbx.Or(dbx.HashExp{"uuid": "9e5081e6-4c56-57b9-9965-f6dc74559755"}, dbx.HashExp{"uuid": "48cd8c4e-fb70-595c-9dfb-7035f56326d9"}),
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := buildIcalQueryForModules(tt.args.modules); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("buildIcalQueryForModules() = %v, want %v", got, tt.want)
			}
		})
	}
}
