Skip to content

Commit 8b31048

Browse files
authored
Merge remote-tracking branch 'origin/main' into fix/notifications
# Conflicts: # apps/game-client/src/features/settings/components/detector/detector-routing-settings-tab-form.test.tsx # apps/game-client/src/i18n/translations/settings.json
2 parents 6c2211a + 1e5ecf4 commit 8b31048

25 files changed

Lines changed: 707 additions & 44 deletions

apps/api/openapi.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5179,6 +5179,8 @@ components:
51795179
id:
51805180
type: string
51815181
minLength: 1
5182+
name:
5183+
type: string
51825184
minLevel:
51835185
type: number
51845186
minimum: 0
@@ -5187,6 +5189,8 @@ components:
51875189
type: number
51885190
minimum: 0
51895191
maximum: 500
5192+
world:
5193+
type: string
51905194
guildIds:
51915195
type: array
51925196
items:
@@ -5416,6 +5420,8 @@ components:
54165420
id:
54175421
type: string
54185422
minLength: 1
5423+
name:
5424+
type: string
54195425
minLevel:
54205426
type: number
54215427
minimum: 0
@@ -5424,6 +5430,8 @@ components:
54245430
type: number
54255431
minimum: 0
54265432
maximum: 500
5433+
world:
5434+
type: string
54275435
guildIds:
54285436
type: array
54295437
items:

apps/api/src/shared/dto/user-account-preferences-response.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ const NotificationsSettingsSchema = z.object({
2121

2222
const DetectorRoutingRuleSchema = z.object({
2323
id: z.string().min(1),
24+
name: z.string().optional(),
2425
minLevel: z.number().min(0).max(500),
2526
maxLevel: z.number().min(0).max(500),
27+
world: z.string().optional(),
2628
guildIds: z.array(z.string()),
2729
});
2830

apps/api/src/users/dto/update-user-account-preferences.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ const PartialNotificationSettingsSchema = z.object({
1212

1313
const DetectorRoutingRuleSchema = z.object({
1414
id: z.string().min(1),
15+
name: z.string().optional(),
1516
minLevel: z.number().min(0).max(500),
1617
maxLevel: z.number().min(0).max(500),
18+
world: z.string().optional(),
1719
guildIds: z.array(z.string()),
1820
});
1921

apps/api/src/users/users.service.spec.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,10 @@ describe("UsersService", () => {
488488
routingRules: [
489489
{
490490
id: "hero-range-1",
491+
name: "Hero route",
491492
minLevel: 100,
492493
maxLevel: 200,
494+
world: "pandora",
493495
guildIds: ["guild-2"],
494496
},
495497
],
@@ -513,8 +515,10 @@ describe("UsersService", () => {
513515
routingRules: [
514516
{
515517
id: "hero-range-1",
518+
name: "Hero route",
516519
minLevel: 100,
517520
maxLevel: 200,
521+
world: "pandora",
518522
guildIds: ["guild-2"],
519523
},
520524
],
@@ -533,8 +537,10 @@ describe("UsersService", () => {
533537
routingRules: [
534538
{
535539
id: "hero-range-1",
540+
name: "Hero route",
536541
minLevel: 100,
537542
maxLevel: 200,
543+
world: "pandora",
538544
guildIds: ["guild-2"],
539545
},
540546
],
@@ -564,6 +570,7 @@ describe("UsersService", () => {
564570
id: "",
565571
minLevel: 220,
566572
maxLevel: 120,
573+
world: " Pandora ",
567574
guildIds: ["guild-1", 123, "guild-2"],
568575
},
569576
],
@@ -586,6 +593,7 @@ describe("UsersService", () => {
586593
id: "rule-1",
587594
minLevel: 120,
588595
maxLevel: 220,
596+
world: "Pandora",
589597
guildIds: ["guild-1", "guild-2"],
590598
},
591599
],
@@ -597,6 +605,71 @@ describe("UsersService", () => {
597605
});
598606
});
599607

608+
it("trims detector routing rule names and keeps old rules without name", async () => {
609+
mockPrismaService.userGameAccountSettings.findUnique.mockResolvedValue({
610+
id: 10,
611+
userId: "auth-user-current",
612+
accountId: "444",
613+
settings: {
614+
detector: {
615+
HERO: {
616+
detect: true,
617+
notifyWindow: true,
618+
highlight: true,
619+
notifySound: false,
620+
},
621+
routingRules: [
622+
{
623+
id: "rule-with-name",
624+
name: " Bossy hero ",
625+
minLevel: 100,
626+
maxLevel: 200,
627+
guildIds: ["guild-1"],
628+
},
629+
{
630+
id: "rule-without-name",
631+
minLevel: 210,
632+
maxLevel: 300,
633+
guildIds: ["guild-2"],
634+
},
635+
],
636+
},
637+
},
638+
createdAt: new Date(),
639+
updatedAt: new Date(),
640+
});
641+
642+
const result = await service.getUserGameAccountPreferences(
643+
"auth-user-current",
644+
"444",
645+
);
646+
647+
expect(result).toEqual({
648+
accountId: "444",
649+
detector: expect.objectContaining({
650+
routingRules: [
651+
{
652+
id: "rule-with-name",
653+
name: "Bossy hero",
654+
minLevel: 100,
655+
maxLevel: 200,
656+
guildIds: ["guild-1"],
657+
},
658+
{
659+
id: "rule-without-name",
660+
minLevel: 210,
661+
maxLevel: 300,
662+
guildIds: ["guild-2"],
663+
},
664+
],
665+
}),
666+
hasStoredDetector: true,
667+
hasStoredNotifications: false,
668+
hasStoredPreferences: true,
669+
notifications: defaultNotificationsSettings,
670+
});
671+
});
672+
600673
it("deletes auth-owned and discord-owned records with the correct identifiers", async () => {
601674
await service.deleteAccount({
602675
authUserId: "auth-user-current",

apps/api/src/users/users.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,14 +773,19 @@ export class UsersService {
773773
);
774774
const minLevel = Math.min(normalizedMinLevel, normalizedMaxLevel);
775775
const maxLevel = Math.max(normalizedMinLevel, normalizedMaxLevel);
776+
const name = typeof rule.name === "string" ? rule.name.trim() : undefined;
777+
const world =
778+
typeof rule.world === "string" ? rule.world.trim() : undefined;
776779

777780
acc.push({
778781
id:
779782
typeof rule.id === "string" && rule.id.length > 0
780783
? rule.id
781784
: `rule-${index + 1}`,
785+
name: name && name.length > 0 ? name : undefined,
782786
minLevel,
783787
maxLevel,
788+
world: world && world.length > 0 ? world : undefined,
784789
guildIds: Array.isArray(rule.guildIds)
785790
? rule.guildIds.filter(
786791
(guildId): guildId is string => typeof guildId === "string",

0 commit comments

Comments
 (0)