Skip to content

Commit

Permalink
Merge pull request #332 from NibiruChain/develop
Browse files Browse the repository at this point in the history
chore: develop -> main
  • Loading branch information
cgilbe27 authored Mar 6, 2024
2 parents 18cc31b + 4e1144d commit 4f74990
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 43 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
12 changes: 6 additions & 6 deletions src/gql/heart-monitor/heart-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ import {
MarketingFields,
QueryMarketingArgs,
marketingQuery,
GQLMarketingMutationGqlUpdateTwitterUserArgs,
marketingMutation,
GqlOutMarketingMutation,
GQLTwitterUser,
DeepPartial,
QueryMarketingMutationArgs,
GQLMarketingMutationFields,
} from ".."

/** IHeartMonitor is an interface for a Heart Monitor GraphQL API.
Expand Down Expand Up @@ -154,9 +154,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 +338,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)
4 changes: 2 additions & 2 deletions src/gql/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ export * from "./featureFlags"
export * from "./governance"
export * from "./ibc"
export * from "./inflation"
export * from "./markPriceCandles"
export * from "./marketing"
export * from "./markPriceCandles"
export * from "./oracle"
export * from "./perp"
export * from "./redelegations"
export * from "./spotLpPositions"
export * from "./spotPoolCreated"
export * from "./spotPoolExited"
export * from "./spotPoolJoined"
export * from "./spotPoolSwap"
export * from "./spotPools"
export * from "./spotPoolSwap"
export * from "./stats"
export * from "./unbondings"
export * from "./users"
Expand Down
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
9 changes: 7 additions & 2 deletions src/gql/utils/defaultObjects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
GQLAccountLinksInfo,
GQLBlock,
GQLDelegation,
GQLDistributionCommission,
Expand Down Expand Up @@ -452,11 +453,9 @@ export const defaultTwitterUser: GQLTwitterUser = {
displayName: "",
followersCount: 0,
followingCount: 0,
discordId: "",
id: "",
likes: [],
listedCount: 0,
nibiAddress: "",
tweets: [],
tweetsCount: 0,
username: "",
Expand Down Expand Up @@ -503,3 +502,9 @@ export const defaultTaskCompletion: GQLTaskCompletion = {
task: defaultTask,
user: defaultTwitterUser,
}

export const defaultAccountLinksInfo: GQLAccountLinksInfo = {
nibiAddress: "",
discordId: "",
twitterUser: defaultTwitterUser,
}

1 comment on commit 4f74990

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 88%
90.23% (1266/1403) 79.55% (541/680) 78.28% (310/396)

Please sign in to comment.