Skip to content

Commit

Permalink
feat: scaffold Claim feature
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Apr 5, 2024
1 parent 1d30478 commit a3be194
Show file tree
Hide file tree
Showing 98 changed files with 3,139 additions and 59 deletions.
81 changes: 81 additions & 0 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,76 @@ type AppConfig {
authTwitterEnabled: Boolean!
}

type Claim {
amount: String!
communityId: String!
createdAt: DateTime
id: String!
minter: String!
name: String!
provider: IdentityProvider!
providerId: String!
signature: String
status: ClaimStatus!
updatedAt: DateTime
}

input ClaimAdminCreateInput {
amount: String
communityId: String!
minter: String!
provider: IdentityProvider!
providerId: String!
}

input ClaimAdminFindManyInput {
communityId: String!
limit: Int = 10
page: Int = 1
search: String
}

input ClaimAdminUpdateInput {
amount: String
signature: String
status: ClaimStatus
}

type ClaimPaging {
data: [Claim!]!
meta: PagingMeta!
}

enum ClaimStatus {
Claimed
Pending
}

input ClaimUserCreateInput {
amount: String
communityId: String!
minter: String!
provider: IdentityProvider!
providerId: String!
}

input ClaimUserFindManyInput {
communityId: String!
limit: Int = 10
minter: String
page: Int = 1
provider: IdentityProvider
providerId: String
search: String
status: ClaimStatus
}

input ClaimUserUpdateInput {
amount: String
signature: String
status: ClaimStatus
}

type Community {
createdAt: DateTime
description: String!
Expand Down Expand Up @@ -184,19 +254,22 @@ input LoginInput {
}

type Mutation {
adminCreateClaim(input: ClaimAdminCreateInput!): Claim
adminCreateCommunityMember(input: AdminCreateCommunityMemberInput!): CommunityMember
adminCreateIdentity(input: AdminCreateIdentityInput!): Identity
adminCreatePreset(input: PresetAdminCreateInput!): Preset
adminCreatePrice(input: PriceAdminCreateInput!): Price
adminCreateUser(input: AdminCreateUserInput!): User
adminCreateWallet(input: WalletAdminCreateInput!): Wallet
adminDeleteClaim(claimId: String!): Boolean
adminDeleteCommunity(communityId: String!): Boolean
adminDeleteCommunityMember(communityMemberId: String!): Boolean
adminDeleteIdentity(identityId: String!): Boolean
adminDeletePreset(presetId: String!): Boolean
adminDeletePrice(priceId: String!): Boolean
adminDeleteUser(userId: String!): Boolean
adminDeleteWallet(walletId: String!): Boolean
adminUpdateClaim(claimId: String!, input: ClaimAdminUpdateInput!): Claim
adminUpdateCommunity(communityId: String!, input: AdminUpdateCommunityInput!): Community
adminUpdateCommunityMember(communityMemberId: String!, input: AdminUpdateCommunityMemberInput!): CommunityMember
adminUpdatePreset(input: PresetAdminUpdateInput!, presetId: String!): Preset
Expand All @@ -208,17 +281,21 @@ type Mutation {
logout: Boolean
register(input: RegisterInput!): User
solanaRequestAirdrop(account: String!): JSON
userCreateClaim(input: ClaimUserCreateInput!): Claim
userCreateCommunity(input: UserCreateCommunityInput!): Community
userCreateCommunityMember(input: UserCreateCommunityMemberInput!): CommunityMember
userCreateMintFromMinter(account: String!, communitySlug: String!): String
userCreateMintFromPreset(communitySlug: String!, presetId: String!): String
userCreateWallet(input: WalletUserCreateInput!): Wallet
userDeleteClaim(claimId: String!): Boolean
userDeleteCommunity(communityId: String!): Boolean
userDeleteCommunityMember(communityMemberId: String!): Boolean
userDeleteIdentity(identityId: String!): Boolean
userDeleteMinter(account: String!): Boolean
userDeleteWallet(publicKey: String!): Boolean
userLinkIdentity(input: LinkIdentityInput!): Identity
userSetWalletFeepayer(publicKey: String!): Wallet
userUpdateClaim(claimId: String!, input: ClaimUserUpdateInput!): Claim
userUpdateCommunity(communityId: String!, input: UserUpdateCommunityInput!): Community
userUpdateCommunityMember(communityMemberId: String!, input: UserUpdateCommunityMemberInput!): CommunityMember
userUpdateUser(input: UserUpdateUserInput!): User
Expand Down Expand Up @@ -314,13 +391,15 @@ input PriceUserFindManyInput {
}

type Query {
adminFindManyClaim(input: ClaimAdminFindManyInput!): ClaimPaging!
adminFindManyCommunity(input: AdminFindManyCommunityInput!): CommunityPaging!
adminFindManyCommunityMember(input: AdminFindManyCommunityMemberInput!): CommunityMemberPaging!
adminFindManyIdentity(input: AdminFindManyIdentityInput!): [Identity!]
adminFindManyPreset(input: PresetAdminFindManyInput!): PresetPaging!
adminFindManyPrice(input: PriceAdminFindManyInput!): [Price!]!
adminFindManyUser(input: AdminFindManyUserInput!): UserPaging!
adminFindManyWallet(input: WalletAdminFindManyInput!): WalletPaging!
adminFindOneClaim(claimId: String!): Claim
adminFindOneCommunity(communityId: String!): Community
adminFindOneCommunityMember(communityMemberId: String!): CommunityMember
adminFindOnePreset(presetId: String!): Preset
Expand All @@ -337,13 +416,15 @@ type Query {
solanaGetTokenAccounts(account: String!): JSON
solanaGetTransactions(account: String!): JSON
uptime: Float!
userFindManyClaim(input: ClaimUserFindManyInput!): ClaimPaging!
userFindManyCommunity(input: UserFindManyCommunityInput!): CommunityPaging!
userFindManyCommunityMember(input: UserFindManyCommunityMemberInput!): CommunityMemberPaging!
userFindManyIdentity(input: UserFindManyIdentityInput!): [Identity!]
userFindManyPreset(input: PresetUserFindManyInput!): PresetPaging!
userFindManyPrice(input: PriceUserFindManyInput!): [Price!]!
userFindManyUser(input: UserFindManyUserInput!): UserPaging!
userFindManyWallet(input: WalletUserFindManyInput!): WalletPaging!
userFindOneClaim(claimId: String!): Claim
userFindOneCommunity(slug: String!): Community
userFindOneCommunityMember(communityMemberId: String!): CommunityMember
userFindOnePreset(presetId: String!): Preset
Expand Down
150 changes: 150 additions & 0 deletions apps/api-e2e/src/api/api-claim-admin-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { ClaimAdminCreateInput, ClaimAdminFindManyInput, ClaimAdminUpdateInput, Claim } from '@tokengator-mint/sdk'
import { getAliceCookie, getBobCookie, sdk, uniqueId } from '../support'

describe('api-claim-feature', () => {
describe('api-claim-admin-resolver', () => {
const claimName = uniqueId('acme-claim')

let claimId: string
let cookie: string

beforeAll(async () => {
cookie = await getAliceCookie()
const created = await sdk.adminCreateClaim({ input: { name: claimName } }, { cookie })
claimId = created.data.created.id
})

describe('authorized', () => {
beforeAll(async () => {
cookie = await getAliceCookie()
})

it('should create a claim', async () => {
const input: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}

const res = await sdk.adminCreateClaim({ input }, { cookie })

const item: Claim = res.data.created
expect(item.name).toBe(input.name)
expect(item.id).toBeDefined()
expect(item.createdAt).toBeDefined()
expect(item.updatedAt).toBeDefined()
})

it('should update a claim', async () => {
const createInput: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}
const createdRes = await sdk.adminCreateClaim({ input: createInput }, { cookie })
const claimId = createdRes.data.created.id
const input: ClaimAdminUpdateInput = {
name: uniqueId('claim'),
}

const res = await sdk.adminUpdateClaim({ claimId, input }, { cookie })

const item: Claim = res.data.updated
expect(item.name).toBe(input.name)
})

it('should find a list of claims (find all)', async () => {
const createInput: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}
const createdRes = await sdk.adminCreateClaim({ input: createInput }, { cookie })
const claimId = createdRes.data.created.id

const input: ClaimAdminFindManyInput = {}

const res = await sdk.adminFindManyClaim({ input }, { cookie })

expect(res.data.paging.meta.totalCount).toBeGreaterThan(1)
expect(res.data.paging.data.length).toBeGreaterThan(1)
// First item should be the one we created above
expect(res.data.paging.data[0].id).toBe(claimId)
})

it('should find a list of claims (find new one)', async () => {
const createInput: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}
const createdRes = await sdk.adminCreateClaim({ input: createInput }, { cookie })
const claimId = createdRes.data.created.id

const input: ClaimAdminFindManyInput = {
search: claimId,
}

const res = await sdk.adminFindManyClaim({ input }, { cookie })

expect(res.data.paging.meta.totalCount).toBe(1)
expect(res.data.paging.data.length).toBe(1)
expect(res.data.paging.data[0].id).toBe(claimId)
})

it('should find a claim by id', async () => {
const createInput: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}
const createdRes = await sdk.adminCreateClaim({ input: createInput }, { cookie })
const claimId = createdRes.data.created.id

const res = await sdk.adminFindOneClaim({ claimId }, { cookie })

expect(res.data.item.id).toBe(claimId)
})

it('should delete a claim', async () => {
const createInput: ClaimAdminCreateInput = {
name: uniqueId('claim'),
}
const createdRes = await sdk.adminCreateClaim({ input: createInput }, { cookie })
const claimId = createdRes.data.created.id

const res = await sdk.adminDeleteClaim({ claimId }, { cookie })

expect(res.data.deleted).toBe(true)

const findRes = await sdk.adminFindManyClaim({ input: { search: claimId } }, { cookie })
expect(findRes.data.paging.meta.totalCount).toBe(0)
expect(findRes.data.paging.data.length).toBe(0)
})
})

describe('unauthorized', () => {
let cookie: string
beforeAll(async () => {
cookie = await getBobCookie()
})

it('should not update a claim', async () => {
expect.assertions(1)
try {
await sdk.adminUpdateClaim({ claimId, input: {} }, { cookie })
} catch (e) {
expect(e.message).toBe('Unauthorized: User is not Admin')
}
})

it('should not find a claim by id', async () => {
expect.assertions(1)
try {
await sdk.adminFindOneClaim({ claimId }, { cookie })
} catch (e) {
expect(e.message).toBe('Unauthorized: User is not Admin')
}
})

it('should not delete a claim', async () => {
expect.assertions(1)
try {
await sdk.adminDeleteClaim({ claimId }, { cookie })
} catch (e) {
expect(e.message).toBe('Unauthorized: User is not Admin')
}
})
})
})
})
Loading

0 comments on commit a3be194

Please sign in to comment.