|
| 1 | +import { goBackInTimeFor } from "@/cronjobs/cronjobs.types"; |
1 | 2 | import { AppStatistic } from "@/entities/app-stats/app-stat.entity"; |
2 | 3 | import { EAPP_STAT_KEY } from "@/entities/app-stats/app-stats.types"; |
3 | 4 | import { Encounter } from "@/entities/encounter/encounter.entity"; |
@@ -462,6 +463,75 @@ describe("UserService", () => { |
462 | 463 | }, 10000); |
463 | 464 | }); |
464 | 465 |
|
| 466 | + describe("is nearby logic", () => { |
| 467 | + it("should only define a user as nearby if the lastLocationDateTimeUpdated is not older than 24h", async () => { |
| 468 | + const user1 = await userFactory.persistNewTestUser({ |
| 469 | + dateMode: EDateMode.LIVE, |
| 470 | + location: new PointBuilder().build(600, 600), |
| 471 | + locationLastTimeUpdated: goBackInTimeFor(23, "hours"), |
| 472 | + gender: EGender.WOMAN, |
| 473 | + genderDesire: [EGender.MAN], |
| 474 | + intentions: [EIntention.RELATIONSHIP], |
| 475 | + approachChoice: EApproachChoice.BOTH, |
| 476 | + }); |
| 477 | + const user2 = await userFactory.persistNewTestUser({ |
| 478 | + dateMode: EDateMode.LIVE, |
| 479 | + location: new PointBuilder().build(0, 0), |
| 480 | + locationLastTimeUpdated: goBackInTimeFor(23, "hours"), |
| 481 | + gender: EGender.WOMAN, |
| 482 | + genderDesire: [EGender.MAN], |
| 483 | + intentions: [EIntention.RELATIONSHIP], |
| 484 | + approachChoice: EApproachChoice.BOTH, |
| 485 | + }); |
| 486 | + const user3 = await userFactory.persistNewTestUser({ |
| 487 | + dateMode: EDateMode.LIVE, |
| 488 | + location: new PointBuilder().build(0, 0), |
| 489 | + locationLastTimeUpdated: goBackInTimeFor(25, "hours"), |
| 490 | + gender: EGender.WOMAN, |
| 491 | + genderDesire: [EGender.MAN], |
| 492 | + intentions: [EIntention.RELATIONSHIP], |
| 493 | + approachChoice: EApproachChoice.BOTH, |
| 494 | + }); |
| 495 | + const user4 = await userFactory.persistNewTestUser({ |
| 496 | + dateMode: EDateMode.LIVE, |
| 497 | + location: new PointBuilder().build(0, 0), |
| 498 | + locationLastTimeUpdated: goBackInTimeFor(23, "hours"), |
| 499 | + isActive: false, |
| 500 | + gender: EGender.WOMAN, |
| 501 | + genderDesire: [EGender.MAN], |
| 502 | + intentions: [EIntention.RELATIONSHIP], |
| 503 | + approachChoice: EApproachChoice.BOTH, |
| 504 | + }); |
| 505 | + const user5 = await userFactory.persistNewTestUser({ |
| 506 | + dateMode: EDateMode.LIVE, |
| 507 | + location: null, |
| 508 | + locationLastTimeUpdated: goBackInTimeFor(23, "hours"), |
| 509 | + gender: EGender.WOMAN, |
| 510 | + genderDesire: [EGender.MAN], |
| 511 | + intentions: [EIntention.RELATIONSHIP], |
| 512 | + approachChoice: EApproachChoice.BOTH, |
| 513 | + }); |
| 514 | + |
| 515 | + const userIds = [user1.id, user2.id, user3.id, user4.id, user5.id]; |
| 516 | + expect(userIds.length).toEqual( |
| 517 | + (await userService.findAll()).length, |
| 518 | + ); |
| 519 | + |
| 520 | + const nearbyUserIds = await userService.findUsersNearbyByUserIds( |
| 521 | + userIds, |
| 522 | + new PointBuilder().build(0, 0), |
| 523 | + 1500, |
| 524 | + ); |
| 525 | + expect(nearbyUserIds.find((id) => id === user1.id)).toBeUndefined(); // @dev location wise not nearby |
| 526 | + expect(nearbyUserIds.find((id) => id === user2.id)).toEqual( |
| 527 | + user2.id, |
| 528 | + ); // @dev location and time wise nearby |
| 529 | + expect(nearbyUserIds.find((id) => id === user3.id)).toBeUndefined(); // @dev location wise nearby but location too old |
| 530 | + expect(nearbyUserIds.find((id) => id === user4.id)).toBeUndefined(); // @dev nearby but account inactive |
| 531 | + expect(nearbyUserIds.find((id) => id === user5.id)).toBeUndefined(); // @dev nearby but no location available |
| 532 | + }); |
| 533 | + }); |
| 534 | + |
465 | 535 | describe("encounter lookup", function () { |
466 | 536 | it("should not find matches if 2 people already met", async () => { |
467 | 537 | const mainUser = await userFactory.persistNewTestUser({ |
|
0 commit comments