Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy #6277

Merged
merged 9 commits into from
Nov 28, 2024
1 change: 0 additions & 1 deletion src/lib/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const FEATURE_FLAGS_LIST = [
"diamond_blurhash-enabled-globally",
"onyx_enable-home-view-section-featured-fairs",
"diamond_home-view-marketing-collection-categories",
"emerald_home-view-tasks-section",
"onyx_experiment_home_view_test",
] as const

Expand Down
20 changes: 20 additions & 0 deletions src/lib/loaders/loaders_with_authentication/gravity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ export default (accessToken, userID, opts) => {
{},
{ method: "PUT" }
),
updateViewingRoomLoader: gravityLoader(
(id) => `viewing_room/${id}`,
{},
{ method: "PUT" }
),
updateViewingRoomArtworksLoader: gravityLoader(
(id) => `viewing_room/${id}/viewing_room_artworks`,
{},
{ method: "PUT" }
),
updateViewingRoomSubsectionsLoader: gravityLoader(
(id) => `viewing_room/${id}/subsections`,
{},
{ method: "PUT" }
),
deleteHeroUnitLoader: gravityLoader(
(id) => `hero_units/${id}`,
{},
Expand Down Expand Up @@ -289,6 +304,11 @@ export default (accessToken, userID, opts) => {
{},
{ method: "DELETE" }
),
deleteViewingRoomLoader: gravityLoader(
(id) => `viewing_room/${id}`,
{},
{ method: "DELETE" }
),
dislikeArtworkLoader: gravityLoader(
(id) => `collection/disliked-artwork/artwork/${id}`,
{},
Expand Down
17 changes: 17 additions & 0 deletions src/lib/stitching/gravity/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,30 @@ export const executableGravitySchema = () => {

duplicatedTypes.push("CreateViewingRoomPayload")
duplicatedTypes.push("CreateViewingRoomInput")
duplicatedTypes.push("DeleteViewingRoomInput")
duplicatedTypes.push("DeleteViewingRoomPayload")
duplicatedTypes.push("ViewingRoomOrErrorsUnion")
duplicatedTypes.push("ViewingRoomAttributes")
duplicatedTypes.push("UpdateViewingRoomPayload")
duplicatedTypes.push("UpdateViewingRoomArtworksInput")
duplicatedTypes.push("PublishViewingRoomInput")
duplicatedTypes.push("PublishViewingRoomPayload")
duplicatedTypes.push("UnpublishViewingRoomInput")
duplicatedTypes.push("UnpublishViewingRoomPayload")
duplicatedTypes.push("UpdateViewingRoomArtworksPayload")
duplicatedTypes.push("UpdateViewingRoomSubsectionsInput")
duplicatedTypes.push("UpdateViewingRoomSubsectionsPayload")
}

const excludedMutations: string[] = []
if (config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA) {
excludedMutations.push("createViewingRoom")
excludedMutations.push("deleteViewingRoom")
excludedMutations.push("publishViewingRoom")
excludedMutations.push("unpublishViewingRoom")
excludedMutations.push("updateViewingRoom")
excludedMutations.push("updateViewingRoomArtworks")
excludedMutations.push("updateViewingRoomSubsections")
}

// Types which come from Gravity that are not (yet) needed in MP.
Expand Down
1 change: 1 addition & 0 deletions src/schema/v2/artwork/__tests__/artwork.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5129,6 +5129,7 @@ describe("Artwork type", () => {
describe("runningShow", () => {
it("returns the show or fair if the artwork id is in a running show or fair", async () => {
artwork.purchasable = true
artwork.show_ids = ["show-id"]
context.showsLoader.mockResolvedValue([
{
name: "Test Show",
Expand Down
7 changes: 5 additions & 2 deletions src/schema/v2/artwork/collectorSignals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ export const CollectorSignals: GraphQLFieldConfig<any, ResolverContext> = {
type: Show.type,
description:
"Most recent running Show or Fair booth the artwork is currently in, sorted by relevance",
resolve: async (artwork, {}, ctx) => {
resolve: async ({ show_ids }, {}, ctx) => {
if (!show_ids || show_ids.length === 0) {
return null
}
const showOrFair = await await ctx.showsLoader({
artwork: artwork._id,
id: show_ids,
size: 1,
status: "running",
has_location: true,
Expand Down
25 changes: 14 additions & 11 deletions src/schema/v2/artwork/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Context: GraphQLFieldConfig<any, ResolverContext> = {
type: ArtworkContextType,
description: "Returns the associated Fair/Sale/Show",
resolve: (
{ id, sale_ids },
{ id, sale_ids, show_ids },
_options,
{ salesLoader, relatedFairsLoader, showsLoader }
) => {
Expand All @@ -58,21 +58,24 @@ const Context: GraphQLFieldConfig<any, ResolverContext> = {
return assign({ context_type: "Fair" }, fair)
})

const show_promise = showsLoader({
artwork: id,
size: 1,
at_a_fair: false,
})
.then(first)
.then((show) => {
if (!show) return null
return assign({ context_type: "Show" }, show)
let showPromise
if (show_ids && show_ids.length > 0) {
showPromise = showsLoader({
id: show_ids,
size: 1,
at_a_fair: false,
})
.then(first)
.then((show) => {
if (!show) return null
return assign({ context_type: "Show" }, show)
})
}

return Promise.all([
sale_promise || Promise.resolve(null),
fair_promise,
show_promise,
showPromise || Promise.resolve(null),
]).then(choose)
},
}
Expand Down
8 changes: 8 additions & 0 deletions src/schema/v2/homeView/__tests__/HomeView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ describe("homeView", () => {
expect(homeView.sectionsConnection).toMatchInlineSnapshot(`
{
"edges": [
{
"node": {
"__typename": "HomeViewSectionTasks",
"component": {
"title": "Act Now",
},
},
},
{
"node": {
"__typename": "HomeViewSectionActivity",
Expand Down
1 change: 0 additions & 1 deletion src/schema/v2/homeView/sections/Tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const Tasks: HomeViewSection = {
component: {
title: "Act Now",
},
featureFlag: "emerald_home-view-tasks-section",
requiresAuthentication: true,
resolver: withHomeViewTimeout(async (_parent, args, { meTasksLoader }) => {
if (!meTasksLoader) return null
Expand Down
38 changes: 0 additions & 38 deletions src/schema/v2/homeView/sections/__tests__/Tasks.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { isFeatureFlagEnabled } from "lib/featureFlags"
import gql from "lib/gql"
import { runQuery } from "schema/v2/test/utils"

jest.mock("lib/featureFlags", () => ({
isFeatureFlagEnabled: jest.fn(() => true),
}))

const mockIsFeatureFlagEnabled = isFeatureFlagEnabled as jest.Mock

describe("HomeViewSectionTasks", () => {
beforeAll(() => {
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
if (flag === "emerald_home-view-tasks-section") return true
})
})

it("returns the section's metadata", async () => {
const query = gql`
{
Expand Down Expand Up @@ -133,33 +124,4 @@ describe("HomeViewSectionTasks", () => {
}
`)
})

describe("when the feature flag is disabled", () => {
beforeAll(() => {
mockIsFeatureFlagEnabled.mockImplementation((flag: string) => {
if (flag === "emerald_home-view-tasks-section") return false
})
})

it("throws an error when accessed by id", async () => {
const query = gql`
{
homeView {
section(id: "home-view-section-tasks") {
__typename
component {
title
}
}
}
}
`

const context = {}

await expect(runQuery(query, context)).rejects.toThrow(
"Section is not displayable: home-view-section-tasks"
)
})
})
})
12 changes: 12 additions & 0 deletions src/schema/v2/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ import { deliverSecondFactorMutation } from "./me/secondFactors/mutations/delive
import { enableSecondFactorMutation } from "./me/secondFactors/mutations/enableSecondFactor"
import { createAndSendBackupSecondFactorMutation } from "./users/createAndSendBackupSecondFactorMutation"
import { createViewingRoomMutation } from "./viewingRooms/mutations/createViewingRoomMutation"
import { updateViewingRoomMutation } from "./viewingRooms/mutations/updateViewingRoomMutation"
import { deleteViewingRoomMutation } from "./viewingRooms/mutations/deleteViewingRoomMutation"
import { publishViewingRoomMutation } from "./viewingRooms/mutations/publishViewingRoomMutation"
import { unpublishViewingRoomMutation } from "./viewingRooms/mutations/unpublishViewingRoomMutation"
import { updateViewingRoomArtworksMutation } from "./viewingRooms/mutations/updateViewingRoomArtworks"
import { updateViewingRoomSubsectionsMutation } from "./viewingRooms/mutations/updateViewingRoomSubsections"

const viewingRoomUnstitchedRootField = config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
? {
Expand All @@ -272,6 +278,12 @@ const viewingRoomUnstitchedRootField = config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
const viewingRoomsMutations = config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA
? {
createViewingRoom: createViewingRoomMutation,
deleteViewingRoom: deleteViewingRoomMutation,
publishViewingRoom: publishViewingRoomMutation,
unpublishViewingRoom: unpublishViewingRoomMutation,
updateViewingRoom: updateViewingRoomMutation,
updateViewingRoomArtworks: updateViewingRoomArtworksMutation,
updateViewingRoomSubsections: updateViewingRoomSubsectionsMutation,
}
: ({} as any)

Expand Down
4 changes: 4 additions & 0 deletions src/schema/v2/viewingRoomSubsection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export const ViewingRoomSubsectionType = new GraphQLObjectType<
image: {
type: GravityARImageType,
},
imageURL: {
type: GraphQLString,
resolve: ({ image_url }) => image_url,
},
title: {
type: GraphQLString,
},
Expand Down
10 changes: 10 additions & 0 deletions src/schema/v2/viewingRooms/mutations/ARImageInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GraphQLID, GraphQLInputObjectType, GraphQLNonNull } from "graphql"

export const ARImageInputType = new GraphQLInputObjectType({
name: "ARImageInput",
fields: {
internalID: {
type: new GraphQLNonNull(GraphQLID),
},
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import config from "config"
import gql from "lib/gql"
import { runAuthenticatedQuery } from "schema/v2/test/utils"

describe("deleteViewingRoomMutation", () => {
const mockDeleteViewingRoomLoader = jest.fn()

const context = {
deleteViewingRoomLoader: mockDeleteViewingRoomLoader,
}

const viewingRoomData = {
id: "viewing-room-id",
}

beforeAll(() => {
config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA = true
})

afterAll(() => {
config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA = false
})

beforeEach(() => {
mockDeleteViewingRoomLoader.mockResolvedValue(
Promise.resolve(viewingRoomData)
)
})

afterEach(() => {
mockDeleteViewingRoomLoader.mockReset()
})

const mutation = gql`
mutation {
deleteViewingRoom(input: { viewingRoomID: "viewing-room-id" }) {
__typename
}
}
`

it("correctly calls the deleteViewingRoomLoader", async () => {
await runAuthenticatedQuery(mutation, context)

expect(mockDeleteViewingRoomLoader).toHaveBeenCalledWith("viewing-room-id")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import config from "config"
import gql from "lib/gql"
import { runAuthenticatedQuery } from "schema/v2/test/utils"

describe("publishViewingRoomMutation", () => {
const mockUpdateViewingRoomLoader = jest.fn()

const context = {
updateViewingRoomLoader: mockUpdateViewingRoomLoader,
}

const viewingRoomData = {
id: "viewing-room-id",
}

beforeAll(() => {
config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA = true
})

afterAll(() => {
config.USE_UNSTITCHED_VIEWING_ROOM_SCHEMA = false
})

beforeEach(() => {
mockUpdateViewingRoomLoader.mockResolvedValue(
Promise.resolve(viewingRoomData)
)
})

afterEach(() => {
mockUpdateViewingRoomLoader.mockReset()
})

const mutation = gql`
mutation {
publishViewingRoom(input: { viewingRoomID: "viewing-room-id" }) {
__typename
}
}
`

it("correctly calls the updateViewingRoomLoader", async () => {
await runAuthenticatedQuery(mutation, context)

expect(mockUpdateViewingRoomLoader).toHaveBeenCalledWith(
"viewing-room-id",
{
published: true,
}
)
})
})
Loading