This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock.go
189 lines (174 loc) · 4.71 KB
/
mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package mock
// Mock provides mock a testing db with mock data
//
// The mock data should be predictable
import (
"time"
"github.com/script-development/RT-CV/db"
"github.com/script-development/RT-CV/db/testingdb"
"github.com/script-development/RT-CV/helpers/jsonHelpers"
"github.com/script-development/RT-CV/models"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func init() {
// Key1 is a mock api key
Key1 = &models.APIKey{
M: db.NewM(),
Name: "Key with all roles",
Enabled: true,
Domains: []string{"werk.nl"},
Key: "aaa",
Roles: models.APIKeyRoleAll,
}
// Key2 is a mock api key
Key2 = &models.APIKey{
M: db.NewM(),
Name: "Scraper key",
Enabled: true,
Domains: []string{"werk.nl"},
Key: "bbb",
Roles: models.APIKeyRoleScraper,
}
// Key3 is a mock api key
Key3 = &models.APIKey{
M: db.NewM(),
Name: "Information obtainer key",
Enabled: true,
Domains: []string{"werk.nl"},
Key: "ccc",
Roles: models.APIKeyRoleInformationObtainer,
}
// DashboardKey is the mock key for the dashboard
DashboardKey = &models.APIKey{
M: db.M{
ID: primitive.ObjectID{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
Name: "System login key",
System: true,
Enabled: true,
Domains: []string{"*"},
Key: "ddd",
Roles: models.APIKeyRoleDashboard,
}
// Profile1 contains the first example profile
yearsSinceEducation := 1
Profile1 = &models.Profile{
M: db.NewM(),
Name: "Mock profile 1",
AllowedScrapers: []primitive.ObjectID{Key2.ID},
YearsSinceWork: nil,
Active: true,
MustExpProfession: true,
MustDesiredProfession: false,
MustEducation: true,
MustEducationFinished: true,
MustDriversLicense: true,
YearsSinceEducation: &yearsSinceEducation,
DesiredProfessions: []models.ProfileProfession{{
Name: "Rapper",
}},
ProfessionExperienced: []models.ProfileProfession{{
Name: "Dancer",
}},
DriversLicenses: []models.ProfileDriversLicense{{
Name: "A",
}},
Educations: []models.ProfileEducation{{
Name: "Default",
}},
OnMatch: models.ProfileOnMatch{
SendMail: []models.ProfileSendEmailData{
{Email: "example@script.nl"},
},
},
Zipcodes: []models.ProfileDutchZipcode{{
From: 2000,
To: 8000,
}},
}
// Profile2 contains the second example profile
Profile2 = &models.Profile{
M: db.NewM(),
Name: "Mock profile 2",
AllowedScrapers: []primitive.ObjectID{Key2.ID},
YearsSinceWork: nil,
Active: true,
MustExpProfession: false,
MustDesiredProfession: false,
MustEducation: false,
MustEducationFinished: false,
MustDriversLicense: false,
YearsSinceEducation: nil,
DesiredProfessions: nil,
ProfessionExperienced: nil,
DriversLicenses: nil,
Educations: nil,
Zipcodes: nil,
OnMatch: models.ProfileOnMatch{
SendMail: []models.ProfileSendEmailData{
{Email: "example@script.nl"},
},
},
}
// mockMatch1 contains a example match between profile 1 and a cv
mockMatch1 = &models.Match{
RequestID: primitive.NewObjectID(),
ProfileID: Profile1.ID,
KeyID: Key1.ID,
When: jsonHelpers.RFC3339Nano(time.Now().Add(-(time.Minute * 15))),
ReferenceNr: "a",
ProfessionExperienced: &professionExperienced,
YearsSinceEducation: &yearsSinceEducation,
Education: &matchedEducation,
DriversLicense: true,
}
mockMatch2 = &models.Match{
RequestID: primitive.NewObjectID(),
ProfileID: Profile2.ID,
KeyID: Key2.ID,
When: jsonHelpers.RFC3339Nano(time.Now().Add(-(time.Minute * 7))),
ReferenceNr: "b",
}
}
var (
// Key1 is a mock api key
Key1 *models.APIKey
// Key2 is a mock api key
Key2 *models.APIKey
// Key3 is a mock api key
Key3 *models.APIKey
// DashboardKey is the mock key for the dashboard
DashboardKey *models.APIKey
)
var (
// Profile1 contains the second example profile
Profile1 *models.Profile
// Profile2 contains the second example profile
Profile2 *models.Profile
)
var yearsSinceEducation = 2
var matchedEducation = "MBO 4 ict"
var matchedCourse = "Typecursus"
var professionExperienced = "Dancer"
var (
// mockMatch1 contains a example match between profile 1 and a cv
mockMatch1 *models.Match
mockMatch2 *models.Match
)
// NewMockDB returns an in memory temp testing database with mock data
func NewMockDB() *testingdb.TestConnection {
conn := testingdb.NewDB()
// Insert api keys
conn.UnsafeInsert(
Key1,
Key2,
Key3,
DashboardKey,
)
// Insert profiles
conn.UnsafeInsert(
Profile1,
Profile2,
)
return conn
}