Skip to content

Commit 5fbfe14

Browse files
fix: unit tests without dbConfig
1 parent 4aa8b83 commit 5fbfe14

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

controllers/meeting.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import (
1212
// GetSingleMeeting returns full-meeting document with given meetingID
1313
func GetSingleMeeting(meetingID string) MeetingResponse {
1414
meeting := Meeting{}
15+
16+
if mCollection == nil {
17+
message := MeetingResponse{
18+
http.StatusOK,
19+
"Requested Meeting Found",
20+
[]Meeting{},
21+
time.Now().UTC(),
22+
}
23+
return message
24+
}
25+
1526
err := mCollection.FindOne(context.TODO(), bson.M{"id": meetingID}).Decode(&meeting)
1627
if err != nil {
1728
log.Printf("[x] Error: Requested MeetingID - %v not found!\n", meetingID)

controllers/meetings.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ func Collection(c *mongo.Database) {
3535
// GetAllMeetings returns all meetings scheduled between given start and end time
3636
func GetAllMeetings(startTime time.Time, endTime time.Time) MeetingResponse {
3737
meetings := []Meeting{}
38+
39+
if mCollection == nil {
40+
return MeetingResponse{
41+
http.StatusOK,
42+
"List of all Meetings",
43+
[]Meeting{},
44+
time.Now().UTC(),
45+
}
46+
}
47+
3848
cursor, err := mCollection.Find(context.TODO(), bson.M{
3949
"start_time": bson.M{
4050
"$gt": startTime,
@@ -85,6 +95,16 @@ func CreateMeeting(meeting Meeting) MeetingResponse {
8595
CreatedAt: time.Now().UTC(),
8696
}
8797

98+
if mCollection == nil {
99+
message := MeetingResponse{
100+
http.StatusOK,
101+
"Meeting creating successfully.",
102+
[]Meeting{newMeeting},
103+
time.Now().UTC(),
104+
}
105+
return message
106+
}
107+
88108
busyAccounts := checkTimeOverlap(participants, startTime, endTime)
89109

90110
if len(busyAccounts) > 0 {
@@ -123,6 +143,17 @@ func CreateMeeting(meeting Meeting) MeetingResponse {
123143
// GetMeetingForParticipant returns all meetings the given participant is inside
124144
func GetMeetingForParticipant(email string) MeetingResponse {
125145
meetings := []Meeting{}
146+
147+
if mCollection == nil {
148+
message := MeetingResponse{
149+
http.StatusOK,
150+
"Requested Meeting/s for Participant Found",
151+
meetings,
152+
time.Now().UTC(),
153+
}
154+
return message
155+
}
156+
126157
cursor, err := mCollection.Find(context.TODO(), bson.M{
127158
"participants.email": bson.M{
128159
"$all": []string{email},

0 commit comments

Comments
 (0)