Skip to content

Commit 8bcca6c

Browse files
committed
fix failing tests
1 parent 8a9b465 commit 8bcca6c

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

src/__tests__/clanInventory/room/RoomService/readAllSoulHomeRooms.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ describe('Room.readAllSoulHomeRooms() test suite', () => {
3939
const clearedRoom = clearDBRespDefaultFields(room);
4040

4141
expect(errors).toBeNull();
42-
expect(clearedRoom).toEqual(
43-
expect.objectContaining([existingRoom1, existingRoom2]),
44-
);
42+
expect(clearedRoom).toEqual([existingRoom1, existingRoom2]);
4543
});
4644

4745
it('Should return NOT_FOUND if soul home does not exists', async () => {

src/__tests__/clanInventory/room/RoomService/readPlayerClanRooms.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ describe('Room.readPlayerClanRooms() test suite', () => {
6161
const clearedRoom = clearDBRespDefaultFields(room);
6262

6363
expect(errors).toBeNull();
64-
expect(clearedRoom).toEqual(
65-
expect.objectContaining([existingRoom1, existingRoom2]),
66-
);
64+
expect(clearedRoom).toEqual([existingRoom1, existingRoom2]);
6765
});
6866

6967
it('Should return NOT_FOUND if player does not exists', async () => {

src/__tests__/clanInventory/room/utils/RoomHelperService/getPlayerRooms.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ describe('RoomHelperService.getPlayerRooms() test suite', () => {
5959
const clearedRooms = clearDBRespDefaultFields(rooms);
6060

6161
expect(errors).toBeNull();
62-
expect(clearedRooms).toEqual(
63-
expect.objectContaining([existingRoom1, existingRoom2]),
64-
);
62+
expect(clearedRooms).toEqual([existingRoom1, existingRoom2]);
6563
});
6664

6765
it('Should return NOT_FOUND if player does not exists', async () => {

src/__tests__/itemMover/ItemMoverService/stealItems.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ describe('ItemMoverService.stealItems() test suite', () => {
102102
);
103103
});
104104

105-
//TODO: should return items with updated room_ids
106105
it('Should return moved items', async () => {
107106
const [movedItems, errors] = await itemMoverService.stealItems(
108107
[item1._id, item2._id],
@@ -120,7 +119,6 @@ describe('ItemMoverService.stealItems() test suite', () => {
120119
);
121120
});
122121

123-
//TODO: Should throw No movable items found
124122
it('Should throw NOT_FOUND ServiceError if provided items do not exist', async () => {
125123
const throwingCall = async () => {
126124
await itemMoverService.stealItems(
@@ -133,7 +131,7 @@ describe('ItemMoverService.stealItems() test suite', () => {
133131
await expect(throwingCall).rejects.toThrow(
134132
new APIError({
135133
reason: APIErrorReason.NOT_FOUND,
136-
message: "Cannot read properties of undefined (reading 'soulHomeId')",
134+
message: 'No movable items found',
137135
}),
138136
);
139137
});
@@ -159,7 +157,7 @@ describe('ItemMoverService.stealItems() test suite', () => {
159157
await expect(throwingCall).rejects.toThrow(
160158
new APIError({
161159
reason: APIErrorReason.NOT_FOUND,
162-
message: "Cannot read properties of null (reading 'map')",
160+
message: 'No movable items found',
163161
}),
164162
);
165163
});
@@ -176,7 +174,7 @@ describe('ItemMoverService.stealItems() test suite', () => {
176174
await expect(throwingCall).rejects.toThrow(
177175
new APIError({
178176
reason: APIErrorReason.NOT_FOUND,
179-
message: "Cannot read properties of undefined (reading 'map')",
177+
message: 'No movable items found',
180178
}),
181179
);
182180
});

src/itemMover/itemMover.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,25 @@ export class ItemMoverService {
127127
* @throws - Throws an error if no movable items are found.
128128
*/
129129
async stealItems(itemIds: string[], stealToken: StealToken, roomId: string) {
130-
const itemSoulHomeIds: { itemId: string; soulHomeId: string }[] =
130+
if (!Array.isArray(itemIds) || itemIds.length === 0) {
131+
throw new APIError({
132+
reason: APIErrorReason.NOT_FOUND,
133+
message: 'No movable items found',
134+
});
135+
}
136+
const itemSoulHomeIds: { itemId: string; soulHomeId: string }[] = (
131137
await Promise.all(
132138
itemIds.map(async (itemId) => {
133139
try {
134140
const soulHomeId =
135141
await this.itemHelperService.getItemSoulHomeId(itemId);
136142
return { itemId, soulHomeId };
137-
} catch (e) {
138-
void e;
143+
} catch {
144+
return undefined;
139145
}
140146
}),
141-
);
147+
)
148+
).filter(Boolean);
142149

143150
const filteredItems = itemSoulHomeIds.filter(
144151
(item) => item.soulHomeId === stealToken.soulHomeId,

0 commit comments

Comments
 (0)