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
132 changes: 132 additions & 0 deletions src/entities/shared/entityTypes.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
7 changes: 6 additions & 1 deletion src/entities/shared/entityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/integration/handleWorldSettingsChanged.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
)
})
})
})

Expand Down
Loading