diff --git a/src/entities/shared/entityTypes.test.ts b/src/entities/shared/entityTypes.test.ts new file mode 100644 index 00000000..9dd0c859 --- /dev/null +++ b/src/entities/shared/entityTypes.test.ts @@ -0,0 +1,132 @@ +import { SceneContentRating } from "decentraland-gatsby/dist/utils/api/Catalyst.types" + +import { isPlace, isWorld } from "./entityTypes" +import { AggregatePlaceAttributes } from "../Place/types" +import { AggregateWorldAttributes, WorldAttributes } from "../World/types" + +const baseWorldAttributes: WorldAttributes = { + id: "testworld.dcl.eth", + world_name: "testworld.dcl.eth", + title: "Test World", + description: null, + image: null, + owner: null, + content_rating: SceneContentRating.TEEN, + categories: [], + likes: 0, + dislikes: 0, + favorites: 0, + like_rate: 0.5, + like_score: 0, + disabled: false, + disabled_at: null, + created_at: new Date(), + updated_at: new Date(), + show_in_places: true, + single_player: false, + skybox_time: null, + is_private: false, + highlighted: false, + highlighted_image: null, + ranking: null, +} + +const aggregateWorldAttributes: AggregateWorldAttributes = { + ...baseWorldAttributes, + user_like: false, + user_dislike: false, + user_favorite: false, + user_visits: 0, + world: true, + contact_name: null, + base_position: "0,0", + deployed_at: null, +} + +const aggregatePlaceAttributes: AggregatePlaceAttributes = { + id: "place-uuid", + world_name: null, + title: "Genesis Plaza", + description: null, + image: null, + owner: null, + content_rating: SceneContentRating.TEEN, + categories: [], + likes: 0, + dislikes: 0, + favorites: 0, + like_rate: 0.5, + like_score: 0, + disabled: false, + disabled_at: null, + created_at: new Date(), + updated_at: new Date(), + base_position: "0,0", + positions: ["0,0"], + contact_name: null, + contact_email: null, + highlighted: false, + highlighted_image: null, + world: false, + world_id: null, + deployed_at: new Date(), + creator_address: null, + sdk: null, + ranking: null, + textsearch: null, + user_like: false, + user_dislike: false, + user_favorite: false, + user_visits: 0, +} + +describe("isWorld", () => { + describe("with a non-aggregate WorldAttributes (e.g. from WorldModel.findByWorldName)", () => { + it("returns true", () => { + expect(isWorld(baseWorldAttributes)).toBe(true) + }) + }) + + describe("with an aggregate AggregateWorldAttributes", () => { + it("returns true", () => { + expect(isWorld(aggregateWorldAttributes)).toBe(true) + }) + }) + + describe("with an aggregate AggregatePlaceAttributes (world: false)", () => { + it("returns false", () => { + expect(isWorld(aggregatePlaceAttributes)).toBe(false) + }) + }) + + describe("with an aggregate AggregatePlaceAttributes that is a world scene (world: true)", () => { + it("returns true via the aggregate world flag", () => { + const worldScenePlace: AggregatePlaceAttributes = { + ...aggregatePlaceAttributes, + world: true, + world_name: "myworld.dcl.eth", + } + expect(isWorld(worldScenePlace)).toBe(true) + }) + }) +}) + +describe("isPlace", () => { + describe("with an aggregate AggregatePlaceAttributes", () => { + it("returns true", () => { + expect(isPlace(aggregatePlaceAttributes)).toBe(true) + }) + }) + + describe("with an aggregate AggregateWorldAttributes", () => { + it("returns false", () => { + expect(isPlace(aggregateWorldAttributes)).toBe(false) + }) + }) + + describe("with a non-aggregate WorldAttributes", () => { + it("returns false", () => { + expect(isPlace(baseWorldAttributes)).toBe(false) + }) + }) +}) diff --git a/src/entities/shared/entityTypes.ts b/src/entities/shared/entityTypes.ts index c7d03873..f70eaecd 100644 --- a/src/entities/shared/entityTypes.ts +++ b/src/entities/shared/entityTypes.ts @@ -34,11 +34,16 @@ export type AnyEntityAttributes = /** * Type guard to check if an entity is a world. * Works for aggregate, non-aggregate, and base entity types. + * For aggregate entities, checks the `world` boolean field. + * For non-aggregate WorldAttributes (e.g. from WorldModel queries), detects via + * `show_in_places`, which is unique to WorldAttributes and absent from PlaceAttributes. */ export function isWorld( entity: AnyEntityAttributes | AggregateBaseEntityAttributes ): entity is WorldAttributes | AggregateWorldAttributes { - return "world" in entity && entity.world === true + return ( + ("world" in entity && entity.world === true) || "show_in_places" in entity + ) } /** diff --git a/test/integration/handleWorldSettingsChanged.test.ts b/test/integration/handleWorldSettingsChanged.test.ts index cb6fe61e..3360718d 100644 --- a/test/integration/handleWorldSettingsChanged.test.ts +++ b/test/integration/handleWorldSettingsChanged.test.ts @@ -1,6 +1,7 @@ import supertest from "supertest" import { handleWorldSettingsChanged } from "../../src/entities/CheckScenes/task/handleWorldSettingsChanged" +import * as SlackUtils from "../../src/entities/Slack/utils" import { createWorldSettingsChangedEvent, createWorldSettingsDowngradeRatingEvent, @@ -157,6 +158,16 @@ describe("handleWorldSettingsChanged integration", () => { expect(response.body.data.content_rating).toBe("T") }) + + it("should call notifyDowngradeRating with the world entity (world_name defined, not undefined base_position)", () => { + expect(SlackUtils.notifyDowngradeRating).toHaveBeenCalledWith( + expect.objectContaining({ + world_name: "existingworld.dcl.eth", + show_in_places: expect.anything(), + }), + expect.any(String) + ) + }) }) })