Skip to content

Commit 7065935

Browse files
committed
feat: implement network asset feature
1 parent 8a25de4 commit 7065935

File tree

124 files changed

+3244
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3244
-190
lines changed

api-schema.graphql

+52-3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ input AdminFindManyLogInput {
9191
userId: String
9292
}
9393

94+
input AdminFindManyNetworkAssetInput {
95+
cluster: NetworkCluster!
96+
limit: Int = 10
97+
page: Int = 1
98+
search: String
99+
type: NetworkTokenType
100+
}
101+
94102
input AdminFindManyNetworkInput {
95103
limit: Int = 10
96104
page: Int = 1
@@ -394,6 +402,7 @@ type Mutation {
394402
adminDeleteIdentity(identityId: String!): Boolean
395403
adminDeleteLog(logId: String!): Boolean
396404
adminDeleteNetwork(networkId: String!): Boolean
405+
adminDeleteNetworkAsset(networkAssetId: String!): Boolean
397406
adminDeleteNetworkToken(networkTokenId: String!): Boolean
398407
adminDeleteRule(ruleId: String!): Boolean
399408
adminDeleteUser(userId: String!): Boolean
@@ -425,6 +434,7 @@ type Mutation {
425434
userDeleteRulePermission(rulePermissionId: String!): Boolean
426435
userLeaveBotServer(botId: String!, serverId: String!): Boolean
427436
userLinkIdentity(input: LinkIdentityInput!): Identity
437+
userRefreshIdentity(identityId: String!): Boolean
428438
userStartBot(botId: String!): Boolean
429439
userStopBot(botId: String!): Boolean
430440
userSyncBotServer(botId: String!, serverId: String!): Boolean
@@ -453,10 +463,28 @@ type Network {
453463
}
454464

455465
type NetworkAsset {
456-
accounts: [String!]!
457-
amount: String!
466+
account: String!
467+
attributes: JSON
468+
balance: String
469+
cluster: NetworkCluster!
470+
createdAt: DateTime
471+
decimals: Int!
458472
group: String
473+
id: String!
474+
imageUrl: String
475+
metadata: JSON
476+
mint: String!
477+
name: String!
459478
owner: String!
479+
program: String
480+
symbol: String
481+
type: NetworkTokenType!
482+
updatedAt: DateTime
483+
}
484+
485+
type NetworkAssetPaging {
486+
data: [NetworkAsset!]!
487+
meta: PagingMeta!
460488
}
461489

462490
enum NetworkCluster {
@@ -519,6 +547,7 @@ type Query {
519547
adminFindManyIdentity(input: AdminFindManyIdentityInput!): [Identity!]
520548
adminFindManyLog(input: AdminFindManyLogInput!): LogPaging!
521549
adminFindManyNetwork(input: AdminFindManyNetworkInput!): NetworkPaging!
550+
adminFindManyNetworkAsset(input: AdminFindManyNetworkAssetInput!): NetworkAssetPaging!
522551
adminFindManyNetworkToken(input: AdminFindManyNetworkTokenInput!): NetworkTokenPaging!
523552
adminFindManyRule(input: AdminFindManyRuleInput!): RulePaging!
524553
adminFindManyUser(input: AdminFindManyUserInput!): UserPaging!
@@ -527,6 +556,7 @@ type Query {
527556
adminFindOneCommunityMember(communityMemberId: String!): CommunityMember
528557
adminFindOneLog(logId: String!): Log
529558
adminFindOneNetwork(networkId: String!): Network
559+
adminFindOneNetworkAsset(networkAssetId: String!): NetworkAsset
530560
adminFindOneNetworkToken(networkTokenId: String!): NetworkToken
531561
adminFindOneRule(ruleId: String!): Rule
532562
adminFindOneUser(userId: String!): User
@@ -541,13 +571,16 @@ type Query {
541571
userFindManyCommunityMember(input: UserFindManyCommunityMemberInput!): CommunityMemberPaging!
542572
userFindManyIdentity(input: UserFindManyIdentityInput!): [Identity!]
543573
userFindManyLog(input: UserFindManyLogInput!): LogPaging!
574+
userFindManyNetworkAsset(input: UserFindManyNetworkAssetInput!): NetworkAssetPaging!
544575
userFindManyNetworkToken(input: UserFindManyNetworkTokenInput!): NetworkTokenPaging!
545576
userFindManyRule(input: UserFindManyRuleInput!): RulePaging!
546577
userFindManyUser(input: UserFindManyUserInput!): UserPaging!
547578
userFindOneBot(communityId: String!): Bot
548579
userFindOneCommunity(communityId: String!): Community
549580
userFindOneCommunityMember(communityMemberId: String!): CommunityMember
581+
userFindOneIdentity(provider: IdentityProvider!, providerId: String!): Identity
550582
userFindOneLog(logId: String!): Log
583+
userFindOneNetworkAsset(account: String!, cluster: NetworkCluster!): NetworkAsset
551584
userFindOneRule(ruleId: String!): Rule
552585
userFindOneUser(username: String!): User
553586
userFindOneUserById(userId: String!): User
@@ -585,7 +618,7 @@ type Rule {
585618
type RuleCondition {
586619
account: String
587620
amount: String
588-
asset: NetworkAsset
621+
asset: SolanaNetworkAsset
589622
config: JSON
590623
createdAt: DateTime
591624
filters: JSON
@@ -618,6 +651,13 @@ type RulePermission {
618651
updatedAt: DateTime
619652
}
620653

654+
type SolanaNetworkAsset {
655+
accounts: [String!]!
656+
amount: String!
657+
group: String
658+
owner: String!
659+
}
660+
621661
type User {
622662
avatarUrl: String
623663
createdAt: DateTime
@@ -707,6 +747,15 @@ input UserFindManyLogInput {
707747
userId: String
708748
}
709749

750+
input UserFindManyNetworkAssetInput {
751+
cluster: NetworkCluster!
752+
limit: Int = 10
753+
page: Int = 1
754+
search: String
755+
type: NetworkTokenType
756+
username: String!
757+
}
758+
710759
input UserFindManyNetworkTokenInput {
711760
cluster: NetworkCluster!
712761
limit: Int = 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import {
2+
AdminCreateNetworkAssetInput,
3+
AdminFindManyNetworkAssetInput,
4+
AdminUpdateNetworkAssetInput,
5+
NetworkAsset,
6+
} from '@pubkey-link/sdk'
7+
import { getAliceCookie, getBobCookie, sdk, uniqueId } from '../support'
8+
9+
describe('api-network-asset-feature', () => {
10+
describe('api-network-asset-admin-resolver', () => {
11+
const networkAssetName = uniqueId('acme-network-asset')
12+
let networkAssetId: string
13+
let cookie: string
14+
15+
beforeAll(async () => {
16+
cookie = await getAliceCookie()
17+
const created = await sdk.adminCreateNetworkAsset({ input: { name: networkAssetName } }, { cookie })
18+
networkAssetId = created.data.created.id
19+
})
20+
21+
describe('authorized', () => {
22+
beforeAll(async () => {
23+
cookie = await getAliceCookie()
24+
})
25+
26+
it('should create a network-asset', async () => {
27+
const input: AdminCreateNetworkAssetInput = {
28+
name: uniqueId('network-asset'),
29+
}
30+
31+
const res = await sdk.adminCreateNetworkAsset({ input }, { cookie })
32+
33+
const item: NetworkAsset = res.data.created
34+
expect(item.name).toBe(input.name)
35+
expect(item.id).toBeDefined()
36+
expect(item.createdAt).toBeDefined()
37+
expect(item.updatedAt).toBeDefined()
38+
})
39+
40+
it('should update a network-asset', async () => {
41+
const createInput: AdminCreateNetworkAssetInput = {
42+
name: uniqueId('network-asset'),
43+
}
44+
const createdRes = await sdk.adminCreateNetworkAsset({ input: createInput }, { cookie })
45+
const networkAssetId = createdRes.data.created.id
46+
const input: AdminUpdateNetworkAssetInput = {
47+
name: uniqueId('network-asset'),
48+
}
49+
50+
const res = await sdk.adminUpdateNetworkAsset({ networkAssetId, input }, { cookie })
51+
52+
const item: NetworkAsset = res.data.updated
53+
expect(item.name).toBe(input.name)
54+
})
55+
56+
it('should find a list of networkAssets (find all)', async () => {
57+
const createInput: AdminCreateNetworkAssetInput = {
58+
name: uniqueId('network-asset'),
59+
}
60+
const createdRes = await sdk.adminCreateNetworkAsset({ input: createInput }, { cookie })
61+
const networkAssetId = createdRes.data.created.id
62+
63+
const input: AdminFindManyNetworkAssetInput = {}
64+
65+
const res = await sdk.adminFindManyNetworkAsset({ input }, { cookie })
66+
67+
expect(res.data.paging.meta.totalCount).toBeGreaterThan(1)
68+
expect(res.data.paging.data.length).toBeGreaterThan(1)
69+
// First item should be the one we created above
70+
expect(res.data.paging.data[0].id).toBe(networkAssetId)
71+
})
72+
73+
it('should find a list of networkAssets (find new one)', async () => {
74+
const createInput: AdminCreateNetworkAssetInput = {
75+
name: uniqueId('network-asset'),
76+
}
77+
const createdRes = await sdk.adminCreateNetworkAsset({ input: createInput }, { cookie })
78+
const networkAssetId = createdRes.data.created.id
79+
80+
const input: AdminFindManyNetworkAssetInput = {
81+
search: networkAssetId,
82+
}
83+
84+
const res = await sdk.adminFindManyNetworkAsset({ input }, { cookie })
85+
86+
expect(res.data.paging.meta.totalCount).toBe(1)
87+
expect(res.data.paging.data.length).toBe(1)
88+
expect(res.data.paging.data[0].id).toBe(networkAssetId)
89+
})
90+
91+
it('should find a network-asset by id', async () => {
92+
const createInput: AdminCreateNetworkAssetInput = {
93+
name: uniqueId('network-asset'),
94+
}
95+
const createdRes = await sdk.adminCreateNetworkAsset({ input: createInput }, { cookie })
96+
const networkAssetId = createdRes.data.created.id
97+
98+
const res = await sdk.adminFindOneNetworkAsset({ networkAssetId }, { cookie })
99+
100+
expect(res.data.item.id).toBe(networkAssetId)
101+
})
102+
103+
it('should delete a network-asset', async () => {
104+
const createInput: AdminCreateNetworkAssetInput = {
105+
name: uniqueId('network-asset'),
106+
}
107+
const createdRes = await sdk.adminCreateNetworkAsset({ input: createInput }, { cookie })
108+
const networkAssetId = createdRes.data.created.id
109+
110+
const res = await sdk.adminDeleteNetworkAsset({ networkAssetId }, { cookie })
111+
112+
expect(res.data.deleted).toBe(true)
113+
114+
const findRes = await sdk.adminFindManyNetworkAsset({ input: { search: networkAssetId } }, { cookie })
115+
expect(findRes.data.paging.meta.totalCount).toBe(0)
116+
expect(findRes.data.paging.data.length).toBe(0)
117+
})
118+
})
119+
120+
describe('unauthorized', () => {
121+
let cookie: string
122+
beforeAll(async () => {
123+
cookie = await getBobCookie()
124+
})
125+
126+
it('should not create a network-asset', async () => {
127+
expect.assertions(1)
128+
const input: AdminCreateNetworkAssetInput = {
129+
name: uniqueId('network-asset'),
130+
}
131+
132+
try {
133+
await sdk.adminCreateNetworkAsset({ input }, { cookie })
134+
} catch (e) {
135+
expect(e.message).toBe('Unauthorized: User is not Admin')
136+
}
137+
})
138+
139+
it('should not update a network-asset', async () => {
140+
expect.assertions(1)
141+
try {
142+
await sdk.adminUpdateNetworkAsset({ networkAssetId, input: {} }, { cookie })
143+
} catch (e) {
144+
expect(e.message).toBe('Unauthorized: User is not Admin')
145+
}
146+
})
147+
148+
it('should not find a list of networkAssets (find all)', async () => {
149+
expect.assertions(1)
150+
try {
151+
await sdk.adminFindManyNetworkAsset({ input: {} }, { cookie })
152+
} catch (e) {
153+
expect(e.message).toBe('Unauthorized: User is not Admin')
154+
}
155+
})
156+
157+
it('should not find a network-asset by id', async () => {
158+
expect.assertions(1)
159+
try {
160+
await sdk.adminFindOneNetworkAsset({ networkAssetId }, { cookie })
161+
} catch (e) {
162+
expect(e.message).toBe('Unauthorized: User is not Admin')
163+
}
164+
})
165+
166+
it('should not delete a network-asset', async () => {
167+
expect.assertions(1)
168+
try {
169+
await sdk.adminDeleteNetworkAsset({ networkAssetId }, { cookie })
170+
} catch (e) {
171+
expect(e.message).toBe('Unauthorized: User is not Admin')
172+
}
173+
})
174+
})
175+
})
176+
})

0 commit comments

Comments
 (0)