Skip to content

Commit 26f52d9

Browse files
authored
Merge pull request #385 from wavect/jc/tests-for-intentions
fix: tests for intentions
2 parents cbbb6c4 + defa04e commit 26f52d9

File tree

2 files changed

+81
-10
lines changed

2 files changed

+81
-10
lines changed

backend/src/entities/user/user.repository.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class UserRepository extends Repository<User> {
4141
getAgeRangeParsed(userToBeApproached.ageRangeString),
4242
)
4343
.filterRecentEncounters()
44-
.relatedToUser(userToBeApproached.id)
4544
.withDateModeLiveMode();
4645

4746
return this;
@@ -234,14 +233,6 @@ export class UserRepository extends Repository<User> {
234233
return this;
235234
}
236235

237-
private relatedToUser(userToBeApproachedId: string): this {
238-
this.queryBuilder.andWhere(
239-
"(encounterUser.id = :userToBeApproachedId OR encounterUser.id IS NULL)",
240-
{ userToBeApproachedId },
241-
);
242-
return this;
243-
}
244-
245236
private userWithSuitableApproachSettings(
246237
approachChoice: EApproachChoice,
247238
): this {

backend/test/integration/services/matching.service.spec.ts

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,89 @@ describe("Matching Service Integration Tests ", () => {
214214
expect.arrayContaining([userId.id, userId2.id]),
215215
);
216216
});
217+
it("should only find users that are the right gender and intentions", async () => {
218+
const userId = await userFactory.persistNewTestUser({
219+
gender: EGender.WOMAN,
220+
genderDesire: [EGender.MAN],
221+
intentions: [EIntention.RELATIONSHIP, EIntention.CASUAL],
222+
});
223+
const userId2 = await userFactory.persistNewTestUser({
224+
gender: EGender.WOMAN,
225+
genderDesire: [EGender.MAN],
226+
intentions: [
227+
EIntention.RELATIONSHIP,
228+
EIntention.FRIENDSHIP,
229+
EIntention.RECONNECT_FRIENDS,
230+
],
231+
});
232+
await userFactory.persistNewTestUser({
233+
gender: EGender.WOMAN,
234+
genderDesire: [EGender.MAN],
235+
intentions: [
236+
EIntention.FRIENDSHIP,
237+
EIntention.RECONNECT_FRIENDS,
238+
EIntention.CASUAL,
239+
],
240+
});
241+
242+
const matches = Array.from(
243+
(
244+
await matchingService.findNearbyMatches(testingMainUser)
245+
).values(),
246+
);
247+
248+
expect(matches.length).toBe(2);
249+
expect(matches.map((m) => m.id)).toEqual(
250+
expect.arrayContaining([userId.id, userId2.id]),
251+
);
252+
});
253+
254+
it("should only find users that are the right gender and intentions 2", async () => {
255+
await clearDatabase(testingDataSource);
256+
257+
const birthDay = new Date("1996-09-21");
258+
const testingMainUser2 = await userFactory.persistNewTestUser({
259+
dateMode: EDateMode.LIVE,
260+
location: new PointBuilder().build(0, 0),
261+
genderDesire: [EGender.WOMAN],
262+
gender: EGender.MAN,
263+
intentions: [
264+
EIntention.RELATIONSHIP,
265+
EIntention.CASUAL,
266+
EIntention.FRIENDSHIP,
267+
],
268+
approachChoice: EApproachChoice.APPROACH,
269+
birthDay,
270+
ageRangeString: `[${getAge(birthDay) - User.defaultAgeRange},${getAge(birthDay) + User.defaultAgeRange}]`,
271+
});
272+
273+
const userId2 = await userFactory.persistNewTestUser({
274+
gender: EGender.WOMAN,
275+
genderDesire: [EGender.MAN],
276+
intentions: [EIntention.RELATIONSHIP, EIntention.FRIENDSHIP],
277+
});
278+
279+
const userId3 = await userFactory.persistNewTestUser({
280+
gender: EGender.WOMAN,
281+
genderDesire: [EGender.MAN],
282+
intentions: [EIntention.RELATIONSHIP, EIntention.CASUAL],
283+
});
284+
285+
const matches = Array.from(
286+
(
287+
await matchingService.findNearbyMatches(testingMainUser2)
288+
).values(),
289+
);
290+
291+
expect(matches.length).toBe(2);
292+
expect(matches.map((m) => m.id)).toEqual(
293+
expect.arrayContaining([userId2.id, userId3.id]),
294+
);
295+
});
296+
217297
it("should only find users with a recent location update", async () => {
218298
const now = new Date();
219-
const sixHoursAgo = new Date(now.getTime() - 6 * 60 * 60 * 1000);
299+
const sixHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
220300
const twoHoursAgo = new Date(now.getTime() - 2 * 60 * 60 * 1000);
221301

222302
const baseConfiguration = {

0 commit comments

Comments
 (0)