Skip to content

Commit

Permalink
feat: marketing mutation + query (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilbe27 authored Mar 6, 2024
1 parent 26176e3 commit 61c7fe8
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 48 deletions.
74 changes: 47 additions & 27 deletions src/gql/heart-monitor/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ import {
defaultTask,
QueryMarketingArgs,
MarketingFields,
GQLMarketingMutationGqlUpdateTwitterUserArgs,
GQLTwitterUser,
QueryMarketingMutationArgs,
GQLMarketingMutationFields,
defaultAccountLinksInfo,
} from ".."

const nibiruUrl = "testnet-1"
Expand Down Expand Up @@ -436,43 +437,38 @@ test("markPriceCandlesSubscription", async () => {
})

const testMarketingMutation = async (
args: GQLMarketingMutationGqlUpdateTwitterUserArgs,
fields?: GQLTwitterUser
args: QueryMarketingMutationArgs,
fields?: GQLMarketingMutationFields
) => {
const resp = await heartMonitor.marketingMutation(args, {}, fields)
expect(resp).toHaveProperty("marketing")

if (resp.marketing) {
const { marketing } = resp

checkFields(
[marketing],
[
"completedTasks",
"creationTimestamp",
"displayName",
"followersCount",
"followingCount",
"id",
"likes",
"listedCount",
"nibiAddress",
"tweets",
"tweetsCount",
"username",
]
)
checkFields([marketing], ["updateTwitterUser", "linkAccounts"])
}
}

// Create JIT JWT for this test
test.skip("marketingMutation", async () => {
await testMarketingMutation({
input: {
userId: "800528778854182912",
nibiAddress: "nibi1p6luzkxeufy29reymgjqnl5mv6a6gae07cphed",
displayName: "WildFyre",
username: "wildfyreapp",
updateTwitterUser: {
input: {
userId: "800528778854182912",
nibiAddress: "nibi1p6luzkxeufy29reymgjqnl5mv6a6gae07cphed",
displayName: "WildFyre",
username: "wildfyreapp",
},
},
linkAccounts: {
input: {
nibiAddress: "nibi1p6luzkxeufy29reymgjqnl5mv6a6gae07cphed",
twitterUser: {
displayName: "WildFyre",
username: "wildfyreapp",
},
},
},
})
})
Expand All @@ -489,7 +485,15 @@ const testMarketingQuery = async (

checkFields(
[marketing],
["likes", "retweets", "tasks", "tweets", "twitterUser"]
[
"likes",
"retweets",
"tasks",
"tweets",
"twitterUser",
"accountLinksInfo",
"lastUpdatedTimestamp",
]
)
}
}
Expand All @@ -506,6 +510,12 @@ test.skip("marketingQuery", async () => {
likes: {
where: { userId: "1516130689028087815" },
},
accountLinksInfo: {
where: {
nibiAddress: "nibi1p6luzkxeufy29reymgjqnl5mv6a6gae07cphed",
twitterId: "800528778854182912",
},
},
})
await testMarketingQuery(
{
Expand All @@ -518,21 +528,31 @@ test.skip("marketingQuery", async () => {
likes: {
where: { userId: "" },
},
accountLinksInfo: {
where: {
nibiAddress: "",
twitterId: "",
},
},
},
{
accountLinksInfo: defaultAccountLinksInfo,
twitterUser: defaultTwitterUser,
tweets: defaultTweet,
likes: defaultLike,
tasks: defaultTask,
lastUpdatedTimestamp: "",
}
)
await testMarketingQuery(
{},
{
accountLinksInfo: defaultAccountLinksInfo,
twitterUser: defaultTwitterUser,
tweets: defaultTweet,
likes: defaultLike,
tasks: defaultTask,
lastUpdatedTimestamp: "",
}
)
})
Expand Down
10 changes: 6 additions & 4 deletions src/gql/heart-monitor/heart-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ import {
GqlOutMarketingMutation,
GQLTwitterUser,
DeepPartial,
QueryMarketingMutationArgs,
GQLMarketingMutationFields,
} from ".."

/** IHeartMonitor is an interface for a Heart Monitor GraphQL API.
Expand Down Expand Up @@ -154,9 +156,9 @@ export interface IHeartMonitor {
) => Promise<GqlOutInflation>

readonly marketingMutation: (
args: GQLMarketingMutationGqlUpdateTwitterUserArgs,
args: QueryMarketingMutationArgs,
headers: HeadersInit,
fields?: DeepPartial<GQLTwitterUser>
fields?: DeepPartial<GQLMarketingMutationFields>
) => Promise<GqlOutMarketingMutation>

readonly marketingQuery: (
Expand Down Expand Up @@ -338,9 +340,9 @@ export class HeartMonitor implements IHeartMonitor {
) => marketingQuery(args, this.gqlEndpt, fields)

marketingMutation = async (
args: GQLMarketingMutationGqlUpdateTwitterUserArgs,
args: QueryMarketingMutationArgs,
headers: HeadersInit,
fields?: DeepPartial<GQLTwitterUser>
fields?: DeepPartial<GQLMarketingMutationFields>
) => marketingMutation(args, this.gqlEndpt, headers, fields)

markPriceCandles = async (
Expand Down
74 changes: 68 additions & 6 deletions src/gql/mutation/marketing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,79 @@ import {
GQLTwitterUser,
GQLMarketingMutationGqlUpdateTwitterUserArgs,
DeepPartial,
GQLMarketingMutationGqlLinkAccountsArgs,
GQLAccountLinksInfo,
defaultAccountLinksInfo,
} from ".."

export type QueryMarketingMutationArgs = {
updateTwitterUser?: GQLMarketingMutationGqlUpdateTwitterUserArgs
linkAccounts?: GQLMarketingMutationGqlLinkAccountsArgs
}

export interface GqlOutMarketingMutation {
marketing?: GQLMutation["marketing"]
}

export type GQLMarketingMutationFields = DeepPartial<{
updateTwitterUser?: DeepPartial<GQLTwitterUser>
linkAccounts?: DeepPartial<GQLAccountLinksInfo>
}>

export const marketingMutationString = (
args: GQLMarketingMutationGqlUpdateTwitterUserArgs,
args: QueryMarketingMutationArgs,
excludeParentObject: boolean,
fields?: DeepPartial<GQLTwitterUser>
) =>
`mutation {
fields?: DeepPartial<GQLMarketingMutationFields>
) => {
const GQLMarketingMutationQuery: string[] = []

if (fields?.updateTwitterUser) {
GQLMarketingMutationQuery.push(
gqlQuery(
"updateTwitterUser",
args.updateTwitterUser ?? {},
convertObjectToPropertiesString(fields.updateTwitterUser),
true
)
)
}

if (fields?.linkAccounts) {
GQLMarketingMutationQuery.push(
gqlQuery(
"linkAccounts",
args.linkAccounts ?? {},
convertObjectToPropertiesString(fields.linkAccounts),
true
)
)
}

// Default Objects

if (args.updateTwitterUser && !fields?.updateTwitterUser) {
GQLMarketingMutationQuery.push(
gqlQuery(
"updateTwitterUser",
args.updateTwitterUser,
convertObjectToPropertiesString(defaultTwitterUser),
true
)
)
}

if (args.linkAccounts && !fields?.linkAccounts) {
GQLMarketingMutationQuery.push(
gqlQuery(
"linkAccounts",
args.linkAccounts,
convertObjectToPropertiesString(defaultAccountLinksInfo),
true
)
)
}

return `mutation {
marketing {
${gqlQuery(
"updateTwitterUser",
Expand All @@ -30,11 +91,12 @@ export const marketingMutationString = (
)}
}
}`
}

export const marketingMutation = async (
args: GQLMarketingMutationGqlUpdateTwitterUserArgs,
args: QueryMarketingMutationArgs,
endpt: string,
headers: HeadersInit,
fields?: DeepPartial<GQLTwitterUser>
fields?: DeepPartial<GQLMarketingMutationFields>
): Promise<GqlOutMarketingMutation> =>
doGqlQuery(marketingMutationString(args, true, fields), endpt, headers)
33 changes: 33 additions & 0 deletions src/gql/query/marketing.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
convertObjectToPropertiesString,
DeepPartial,
defaultAccountLinksInfo,
defaultLike,
defaultTask,
defaultTweet,
defaultTwitterUser,
doGqlQuery,
GQLAccountLinksInfo,
GQLLike,
GQLMarketingQueryGqlAccountLinksInfoArgs,
GQLMarketingQueryGqlLikesArgs,
GQLMarketingQueryGqlTasksArgs,
GQLMarketingQueryGqlTweetsArgs,
Expand All @@ -23,6 +26,7 @@ export type QueryMarketingArgs = {
tweets?: GQLMarketingQueryGqlTweetsArgs
likes?: GQLMarketingQueryGqlLikesArgs
tasks?: GQLMarketingQueryGqlTasksArgs
accountLinksInfo?: GQLMarketingQueryGqlAccountLinksInfoArgs
}

export interface GqlOutMarketingQuery {
Expand All @@ -34,6 +38,8 @@ export type MarketingFields = DeepPartial<{
tweets?: DeepPartial<GQLTweet>
likes?: DeepPartial<GQLLike>
tasks?: DeepPartial<GQLTask>
accountLinksInfo?: DeepPartial<GQLAccountLinksInfo>
lastUpdatedTimestamp?: string
}>

export const marketingQueryString = (
Expand Down Expand Up @@ -86,6 +92,17 @@ export const marketingQueryString = (
)
}

if (fields?.accountLinksInfo) {
marketingQuery.push(
gqlQuery(
"accountLinksInfo",
args.accountLinksInfo ?? {},
convertObjectToPropertiesString(fields.accountLinksInfo),
true
)
)
}

// Default Objects

if (args.likes && !fields?.likes) {
Expand Down Expand Up @@ -132,6 +149,22 @@ export const marketingQueryString = (
)
}

if (args.accountLinksInfo && !fields?.accountLinksInfo) {
marketingQuery.push(
gqlQuery(
"accountLinksInfo",
args.accountLinksInfo,
convertObjectToPropertiesString(defaultAccountLinksInfo),
true
)
)
}

// Add lastUpdatedTimestamp if specified
if (fields?.lastUpdatedTimestamp) {
marketingQuery.push("lastUpdatedTimestamp")
}

return `
marketing {
${marketingQuery.join("\n")}
Expand Down
Loading

0 comments on commit 61c7fe8

Please sign in to comment.