Skip to content

feat: add wallet and index-wallet models #5

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ type IndexEntry {
label: String
program: String!
updatedAt: DateTime
wallet: String!
walletId: String!
}

input IndexEntryAdminFindManyInput {
Expand Down Expand Up @@ -137,6 +137,43 @@ input IndexUserFindManyInput {
type: IndexType
}

type IndexWallet {
createdAt: DateTime
id: String!
index: Index
indexId: String!
updatedAt: DateTime
wallet: Wallet
walletId: String!
}

input IndexWalletAdminFindManyInput {
limit: Int = 10
page: Int = 1
search: String
walletId: String!
}

input IndexWalletAdminUpdateInput {
updatedAt: String
}

type IndexWalletPaging {
data: [IndexWallet!]!
meta: PagingMeta!
}

input IndexWalletUserFindManyInput {
limit: Int = 10
page: Int = 1
search: String
walletId: String!
}

input IndexWalletUserUpdateInput {
updatedAt: String
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
Expand All @@ -151,17 +188,27 @@ type Mutation {
adminCreateIdentity(input: IdentityAdminCreateInput!): Identity
adminCreateIndex(input: IndexAdminCreateInput!): Index
adminCreateUser(input: UserAdminCreateInput!): User
adminCreateWallet(input: WalletAdminCreateInput!): Wallet
adminDeleteIdentity(identityId: String!): Boolean
adminDeleteIndex(indexId: String!): Boolean
adminDeleteIndexEntry(indexEntryId: String!): Boolean
adminDeleteIndexWallet(indexWalletId: String!): Boolean
adminDeleteUser(userId: String!): Boolean
adminDeleteWallet(walletId: String!): Boolean
adminUpdateIndex(indexId: String!, input: IndexAdminUpdateInput!): Index
adminUpdateIndexWallet(indexWalletId: String!, input: IndexWalletAdminUpdateInput!): IndexWallet
adminUpdateUser(input: UserAdminUpdateInput!, userId: String!): User
adminUpdateWallet(input: WalletAdminUpdateInput!, walletId: String!): Wallet
login(input: LoginInput!): User
logout: Boolean
register(input: RegisterInput!): User
userCreateWallet(input: WalletUserCreateInput!): Wallet
userDeleteIdentity(identityId: String!): Boolean
userDeleteIndexWallet(indexWalletId: String!): Boolean
userDeleteWallet(walletId: String!): Boolean
userUpdateIndexWallet(indexWalletId: String!, input: IndexWalletUserUpdateInput!): IndexWallet
userUpdateUser(input: UserUserUpdateInput!): User
userUpdateWallet(input: WalletUserUpdateInput!, walletId: String!): Wallet
}

enum NetworkCluster {
Expand All @@ -185,10 +232,14 @@ type Query {
adminFindManyIdentity(input: IdentityAdminFindManyInput!): [Identity!]
adminFindManyIndex(input: IndexAdminFindManyInput!): IndexPaging!
adminFindManyIndexEntry(input: IndexEntryAdminFindManyInput!): IndexEntryPaging!
adminFindManyIndexWallet(input: IndexWalletAdminFindManyInput!): IndexWalletPaging!
adminFindManyUser(input: UserAdminFindManyInput!): UserPaging!
adminFindManyWallet(input: WalletAdminFindManyInput!): WalletPaging!
adminFindOneIndex(indexId: String!): Index
adminFindOneIndexEntry(indexEntryId: String!): IndexEntry
adminFindOneIndexWallet(indexWalletId: String!): IndexWallet
adminFindOneUser(userId: String!): User
adminFindOneWallet(walletId: String!): Wallet
adminGetAccountInfo(input: IndexAdminResolveInput!): JSON
adminResolveIndex(input: IndexAdminResolveInput!): JSON
adminResolveWallet(input: IndexAdminResolveInput!, wallet: String!): JSON
Expand All @@ -198,10 +249,14 @@ type Query {
userFindManyIdentity(input: IdentityUserFindManyInput!): [Identity!]
userFindManyIndex(input: IndexUserFindManyInput!): IndexPaging!
userFindManyIndexEntry(input: IndexEntryUserFindManyInput!): IndexEntryPaging!
userFindManyIndexWallet(input: IndexWalletUserFindManyInput!): IndexWalletPaging!
userFindManyUser(input: UserUserFindManyInput!): UserPaging!
userFindManyWallet(input: WalletUserFindManyInput!): WalletPaging!
userFindOneIndex(indexId: String!): Index
userFindOneIndexEntry(indexEntryId: String!): IndexEntry
userFindOneIndexWallet(indexWalletId: String!): IndexWallet
userFindOneUser(username: String!): User
userFindOneWallet(walletId: String!): Wallet
}

input RegisterInput {
Expand Down Expand Up @@ -272,3 +327,45 @@ input UserUserUpdateInput {
developer: Boolean
name: String
}

type Wallet {
createdAt: DateTime
id: String!
label: String!
updatedAt: DateTime
}

input WalletAdminCreateInput {
id: String!
label: String
}

input WalletAdminFindManyInput {
limit: Int = 10
page: Int = 1
search: String
}

input WalletAdminUpdateInput {
label: String
}

type WalletPaging {
data: [Wallet!]!
meta: PagingMeta!
}

input WalletUserCreateInput {
id: String!
label: String
}

input WalletUserFindManyInput {
limit: Int = 10
page: Int = 1
search: String
}

input WalletUserUpdateInput {
label: String
}
155 changes: 155 additions & 0 deletions apps/api-e2e/src/api/api-index-wallet-admin-feature.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import {
IndexWalletAdminCreateInput,
IndexWalletAdminFindManyInput,
IndexWalletAdminUpdateInput,
IndexWallet,
} from '@pubkey-resolver/sdk'
import { getAliceCookie, getBobCookie, sdk, uniqueId } from '../support'

describe('api-index-wallet-feature', () => {
describe('api-index-wallet-admin-resolver', () => {
const indexWalletName = uniqueId('acme-index-wallet')

let indexWalletId: string
let cookie: string

beforeAll(async () => {
cookie = await getAliceCookie()
const created = await sdk.adminCreateIndexWallet({ input: { name: indexWalletName } }, { cookie })
indexWalletId = created.data.created.id
})

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

it('should create a index-wallet', async () => {
const input: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}

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

const item: IndexWallet = 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 index-wallet', async () => {
const createInput: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}
const createdRes = await sdk.adminCreateIndexWallet({ input: createInput }, { cookie })
const indexWalletId = createdRes.data.created.id
const input: IndexWalletAdminUpdateInput = {
name: uniqueId('index-wallet'),
}

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

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

it('should find a list of indexWallets (find all)', async () => {
const createInput: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}
const createdRes = await sdk.adminCreateIndexWallet({ input: createInput }, { cookie })
const indexWalletId = createdRes.data.created.id

const input: IndexWalletAdminFindManyInput = {}

const res = await sdk.adminFindManyIndexWallet({ 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(indexWalletId)
})

it('should find a list of indexWallets (find new one)', async () => {
const createInput: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}
const createdRes = await sdk.adminCreateIndexWallet({ input: createInput }, { cookie })
const indexWalletId = createdRes.data.created.id

const input: IndexWalletAdminFindManyInput = {
search: indexWalletId,
}

const res = await sdk.adminFindManyIndexWallet({ 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(indexWalletId)
})

it('should find a index-wallet by id', async () => {
const createInput: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}
const createdRes = await sdk.adminCreateIndexWallet({ input: createInput }, { cookie })
const indexWalletId = createdRes.data.created.id

const res = await sdk.adminFindOneIndexWallet({ indexWalletId }, { cookie })

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

it('should delete a index-wallet', async () => {
const createInput: IndexWalletAdminCreateInput = {
name: uniqueId('index-wallet'),
}
const createdRes = await sdk.adminCreateIndexWallet({ input: createInput }, { cookie })
const indexWalletId = createdRes.data.created.id

const res = await sdk.adminDeleteIndexWallet({ indexWalletId }, { cookie })

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

const findRes = await sdk.adminFindManyIndexWallet({ input: { search: indexWalletId } }, { 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 index-wallet', async () => {
expect.assertions(1)
try {
await sdk.adminUpdateIndexWallet({ indexWalletId, input: {} }, { cookie })
} catch (e) {
expect(e.message).toBe('Unauthorized: User is not Admin')
}
})

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

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