Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ describe('ClanHelperService.createDefaultSoulHome() test suite', () => {
expect.arrayContaining([
expect.objectContaining({
room_id: itemsRoom_id,
unityKey: ItemName.SOFA_RAKKAUS,
unityKey: ItemName.COFFEETABLE_RAKKAUS,
}),
expect.objectContaining({
room_id: itemsRoom_id,
unityKey: ItemName.ARMCHAIR_RAKKAUS,
}),
expect.objectContaining({
room_id: itemsRoom_id,
unityKey: ItemName.LAMP_RAKKAUS,
unityKey: ItemName.CEILINGLAMP_RAKKAUS,
}),
expect.objectContaining({
room_id: itemsRoom_id,
unityKey: ItemName.DININGTABLE_RAKKAUS,
}),
expect.objectContaining({
room_id: itemsRoom_id,
unityKey: ItemName.SOFATABLE_RAKKAUS,
unityKey: ItemName.SOFA_RAKKAUS,
}),
expect.objectContaining({
room_id: itemsRoom_id,
Expand Down
10 changes: 9 additions & 1 deletion src/__tests__/clan/data/clan/ClanBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Stall } from '../../../../clan/stall/stall.schema';
import { Environment } from '../../../../common/enum/environment.enum';

export default class ClanBuilder implements IDataBuilder<Clan> {
private static uniqueNameCounter = 0;

private readonly base: Clan = {
_id: undefined,
name: 'clan',
Expand Down Expand Up @@ -49,7 +51,13 @@ export default class ClanBuilder implements IDataBuilder<Clan> {

// Returns a new Clan object with the current base properties
build() {
return { ...this.base };
const clan = { ...this.base };

if (clan.name === 'clan') {
clan.name = `cl-${Date.now().toString(36).slice(-6)}-${ClanBuilder.uniqueNameCounter++}`;
}

return clan;
}

setId(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('HasClanRightsGuard.canActivate() test suite', () => {
const clanBuilder = ClanBuilderFactory.getBuilder('Clan');
const clanRoleBuilder = ClanBuilderFactory.getBuilder('ClanRole');

const existingClan = clanBuilder.build();
let existingClan = clanBuilder.build();
let clanNameCounter = 0;

let reflector: Reflector;

Expand All @@ -57,6 +58,10 @@ describe('HasClanRightsGuard.canActivate() test suite', () => {
providers: [HasClanRightsGuard, Reflector],
}).compile();

existingClan = clanBuilder
.setName(`gc-${Date.now().toString(36).slice(-6)}-${clanNameCounter++}`)
.build();

const clanResp = await clanModel.create(existingClan);
existingClan._id = clanResp._id.toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('getRoomDefaultItems() test suite', () => {
placedOnLocation: [-1, -1],
},
{
...itemProperties.ArmChair_Rakkaus,
...itemProperties.Armchair_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.ARMCHAIR_RAKKAUS,
Expand All @@ -31,10 +31,10 @@ describe('getRoomDefaultItems() test suite', () => {
placedOnLocation: [-1, -1],
},
{
...itemProperties.Lamp_Rakkaus,
...itemProperties.Ceilinglamp_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.LAMP_RAKKAUS,
unityKey: ItemName.CEILINGLAMP_RAKKAUS,
location: [1, 3],
rotation: ItemRotation.FRONT,
position: ItemPosition.FLOOR,
Expand All @@ -53,10 +53,10 @@ describe('getRoomDefaultItems() test suite', () => {
placedOnLocation: [-1, -1],
},
{
...itemProperties.SofaTable_Rakkaus,
...itemProperties.Coffeetable_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.SOFATABLE_RAKKAUS,
unityKey: ItemName.COFFEETABLE_RAKKAUS,
location: [1, 5],
rotation: ItemRotation.FRONT,
position: ItemPosition.FLOOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ describe('ItemHelperService.getItemClanId() test suite', () => {

const clanModel = ClanModule.getClanModel();
const clanBuilder = ClanBuilderFactory.getBuilder('Clan');
const existingClan = clanBuilder.build();
let existingClan = clanBuilder.build();
let clanNameCounter = 0;

beforeEach(async () => {
itemHelperService = await ItemModule.getItemHelperService();

existingClan = clanBuilder
.setName(`ih-${Date.now().toString(36).slice(-6)}-${clanNameCounter++}`)
.build();

const createdClan = await clanModel.create(existingClan);
existingClan._id = createdClan._id;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('ItemService.readMany() test suite', () => {
.setRarityLevel(Rarity.common)
.build();
const item3 = itemBuilder
.setName(ItemName.SOFATABLE_RAKKAUS)
.setName(ItemName.COFFEETABLE_RAKKAUS)
.setRarityLevel(Rarity.common)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('ItemService.updateMany() test suite', () => {
.setRarityLevel(Rarity.common)
.build();
const item3 = itemBuilder
.setName(ItemName.SOFATABLE_RAKKAUS)
.setName(ItemName.COFFEETABLE_RAKKAUS)
.setRarityLevel(Rarity.common)
.build();
const allItemsFilter = { rarity: Rarity.common };
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/clanShop/clanShopService/buyItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ClanShopService.buyItem() test suite', () => {
it('Should successfully start the item buying vote', async () => {
const createdClan = await clanModel.create(clanToCreate);
const createdPlayer = await playerModel.create(playerToCreate);
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

stockToCreate.clan_id = createdClan;
const stock = await stockModel.create(stockToCreate);
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('ClanShopService.buyItem() test suite', () => {
it('Should throw an error if the clan has insufficient funds', async () => {
const createdClan = await clanModel.create(clanToCreate);
const createdPlayer = await playerModel.create(playerToCreate);
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

stockToCreate.clan_id = createdClan;
await stockModel.create(stockToCreate);
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('ClanShopService.buyItem() test suite', () => {
});

it('Should throw an error if the clan does not exist', async () => {
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

const [_, err] = await clanShopService.buyItem(
new ObjectId().toString(),
Expand All @@ -125,7 +125,7 @@ describe('ClanShopService.buyItem() test suite', () => {

it('Should throw an error if the player does not exist', async () => {
const createdClan = await clanModel.create(clanToCreate);
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

stockToCreate.clan_id = createdClan;
await stockModel.create(stockToCreate);
Expand All @@ -146,7 +146,7 @@ describe('ClanShopService.buyItem() test suite', () => {
it('Should throw an error if the voting process fails', async () => {
const createdClan = await clanModel.create(clanToCreate);
const createdPlayer = await playerModel.create(playerToCreate);
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

stockToCreate.clan_id = createdClan;
await stockModel.create(stockToCreate);
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('ClanShopService.buyItem() test suite', () => {

it('Should rollback funds if player does not exist after reserving funds', async () => {
const createdClan = await clanModel.create(clanToCreate);
const itemToBuy = itemProperties['ArmChair_Kylmä_Tulevaisuus'];
const itemToBuy = itemProperties.Armchair_Rakkaus;

stockToCreate.clan_id = createdClan;
await stockModel.create(stockToCreate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ describe('Counter.decrease() test suite', () => {
const clanCreateBuilder = ClanBuilderFactory.getBuilder('Clan');

const startingValue = 10;
const existingClan = clanCreateBuilder.setPlayerCount(startingValue).build();
let clanNameCounter = 0;
let existingClan_id: string;
let filter: any;

beforeEach(async () => {
const existingClan = clanCreateBuilder
.setName(`cd-${Date.now().toString(36).slice(-6)}-${clanNameCounter++}`)
.setPlayerCount(startingValue)
.build();

const dbResp = await clanModel.create(existingClan);
existingClan_id = dbResp._id.toString();
filter = { _id: existingClan_id };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('FleaMarketService.readMany() test suite', () => {
.setRarity(Rarity.common)
.build();
const item3 = fleaMarketItemBuilder
.setName(ItemName.SOFATABLE_RAKKAUS)
.setName(ItemName.COFFEETABLE_RAKKAUS)
.setRarity(Rarity.common)
.build();

Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/fleaMarket/stall/StallService/readAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('StallService.ReadAll() test suite', () => {
);
const furniture2 = await fleaMarketItemModel.create(
fleaMarketItemBuilder
.setName(ItemName.WORK_TABLE)
.setName(ItemName.WORKTABLE_NYKTOPHOBIA)
.setUnityKey('stall-readall-clan2-furniture')
.setClanId(createdClan2._id.toString())
.setIsFurniture(true)
Expand All @@ -118,7 +118,7 @@ describe('StallService.ReadAll() test suite', () => {
expect(result[0].furnitureItems).toEqual([ItemName.CLOSET_RAKKAUS]);

expect(result[1].furnitureItemIds).toEqual([furniture2._id.toString()]);
expect(result[1].furnitureItems).toEqual([ItemName.WORK_TABLE]);
expect(result[1].furnitureItems).toEqual([ItemName.WORKTABLE_NYKTOPHOBIA]);
});

it('Should return only available furniture items belonging to each clan stall', async () => {
Expand All @@ -137,7 +137,7 @@ describe('StallService.ReadAll() test suite', () => {

const clan2StallFurniture = await fleaMarketItemModel.create(
fleaMarketItemBuilder
.setName(ItemName.WORK_TABLE)
.setName(ItemName.WORKTABLE_NYKTOPHOBIA)
.setUnityKey('stall-readall-clan2-available-furniture')
.setClanId(createdClan2._id.toString())
.setIsFurniture(true)
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('StallService.ReadAll() test suite', () => {
expect(result[1].furnitureItemIds).toEqual([
clan2StallFurniture._id.toString(),
]);
expect(result[1].furnitureItems).toEqual([ItemName.WORK_TABLE]);
expect(result[1].furnitureItems).toEqual([ItemName.WORKTABLE_NYKTOPHOBIA]);
});

it('Should return NOT_FOUND error when no clans with stalls', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/itemMover/ItemMoverService/moveItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PlayerModule from '../../player/modules/player.module';

describe('ItemMoverService.moveItem() test suite', () => {
let itemMoverService: ItemMoverService;
let clanNameCounter = 0;

const itemModel = ItemModule.getItemModel();
const itemBuilder = ClanInventoryBuilderFactory.getBuilder('Item');
Expand All @@ -41,14 +42,16 @@ describe('ItemMoverService.moveItem() test suite', () => {

const clanModel = ClanModule.getClanModel();
const clanBuilder = ClanBuilderFactory.getBuilder('Clan');
const existingClan = clanBuilder.build();

const player = LoggedUser.getPlayer();
const playerModel = PlayerModule.getPlayerModel();

beforeEach(async () => {
itemMoverService = await ItemMoverModule.getItemMoverService();

const existingClan = clanBuilder
.setName(`im-${Date.now().toString(36).slice(-8)}-${clanNameCounter++}`)
.build();
const createdClan = await clanModel.create(existingClan);
existingClan._id = createdClan._id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ describe('ExpiredVotingCleanupService.handleExpiredVotingCleanup() test suite',
votings[5].endsOn = expiredDate;
votings[8].endsOn = expiredDate;

await Promise.all(votings.map((v) => votingModel.create(v)));
const createdVotings = await Promise.all(
votings.map((v) => votingModel.create(v)),
);

return {
createdVotingIds: createdVotings.map((voting) => voting._id),
expiredVotingIds: [
createdVotings[5]._id.toString(),
createdVotings[8]._id.toString(),
],
};
};
it('Should delete over week old votings', async () => {
await createTestVotings();
const { createdVotingIds, expiredVotingIds } = await createTestVotings();
await expiredVotingCleanupService['handleExpiredVotingCleanup']();

const votings = await votingModel.find();
const votings = await votingModel.find({ _id: { $in: createdVotingIds } });
expect(votings).toHaveLength(8);
expect(votings.map((voting) => voting._id.toString())).not.toEqual(
expect.arrayContaining(expiredVotingIds),
);
});
});
26 changes: 19 additions & 7 deletions src/__tests__/voting/VotingService/getClanVotings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VotingModule from '../modules/voting.module';
import { VotingService } from '../../../voting/voting.service';
import PlayerBuilderFactory from '../../player/data/playerBuilderFactory';
import PlayerModule from '../../player/modules/player.module';
import { ObjectId } from 'mongodb';

describe('VotingService.getClanVotings() test suite', () => {
let votingService: VotingService;
Expand All @@ -25,19 +26,30 @@ describe('VotingService.getClanVotings() test suite', () => {
};

it('Should return all votings where organizer is the player or their clan', async () => {
const playerToCreate = playerBuilder.setName('john').build();
const player = await playerModel.create(playerToCreate);
const clanId = '67e98660df641b26bb7cbf6b';
const clanId = new ObjectId().toString();
const playerToCreate = playerBuilder
.setName(`voting-${Date.now().toString(36).slice(-6)}`)
.build();
(playerToCreate as any).clan_id = clanId;

await createVotingForOrganizer(player._id.toString(), clanId);
await createVotingForOrganizer(player._id.toString(), clanId);
const player = await playerModel.create(playerToCreate);
const createdVotings = await Promise.all([
createVotingForOrganizer(player._id.toString(), clanId),
createVotingForOrganizer(player._id.toString(), clanId),
]);

const [votings] = await votingService.getClanVotings(player._id.toString());
const returnedVotingIds = votings.map((voting) => voting._id.toString());
const createdVotingIds = createdVotings.map((voting) =>
voting._id.toString(),
);

expect(votings).toHaveLength(2);
expect(returnedVotingIds).toEqual(expect.arrayContaining(createdVotingIds));
expect(
votings.every(
(v) => v.organizer.player_id.toString() === player._id.toString(),
(v) =>
v.organizer.player_id.toString() === player._id.toString() ||
v.organizer.clan_id?.toString() === clanId,
),
).toBe(true);
});
Expand Down
10 changes: 5 additions & 5 deletions src/clan/utils/defaultValues/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function getRoomDefaultItems(room_id: string): CreateItemDto[] {
placedOnLocation: [-1, -1],
},
{
...itemProperties.ArmChair_Rakkaus,
...itemProperties.Armchair_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.ARMCHAIR_RAKKAUS,
Expand All @@ -79,10 +79,10 @@ export function getRoomDefaultItems(room_id: string): CreateItemDto[] {
placedOnLocation: [-1, -1],
},
{
...itemProperties.Lamp_Rakkaus,
...itemProperties.Ceilinglamp_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.LAMP_RAKKAUS,
unityKey: ItemName.CEILINGLAMP_RAKKAUS,
location: [1, 3],
rotation: ItemRotation.FRONT,
position: ItemPosition.FLOOR,
Expand All @@ -101,10 +101,10 @@ export function getRoomDefaultItems(room_id: string): CreateItemDto[] {
placedOnLocation: [-1, -1],
},
{
...itemProperties.SofaTable_Rakkaus,
...itemProperties.Coffeetable_Rakkaus,
stock_id: null,
room_id,
unityKey: ItemName.SOFATABLE_RAKKAUS,
unityKey: ItemName.COFFEETABLE_RAKKAUS,
location: [1, 5],
rotation: ItemRotation.FRONT,
position: ItemPosition.FLOOR,
Expand Down
Loading