Add test for list api keys

This commit is contained in:
Hongbo Wu
2022-05-27 18:33:18 +08:00
parent b7206457b4
commit fa9c5b3efe
2 changed files with 58 additions and 3 deletions

View File

@ -29,9 +29,9 @@ export class ApiKey {
@CreateDateColumn()
createdAt!: Date
@Column('date')
@Column('timestamp')
expiresAt!: Date
@Column('date', { nullable: true })
@Column('timestamp', { nullable: true })
usedAt!: Date | null
}

View File

@ -30,6 +30,7 @@ describe('Api Key resolver', () => {
let query: string
let expiresAt: string
let name: string
let apiKeyId: string
before(async () => {
// create test user and login
@ -102,7 +103,6 @@ describe('Api Key resolver', () => {
describe('revoke api key', () => {
let apiKey: string
let apiKeyId: string
before(async () => {
query = `
@ -153,4 +153,59 @@ describe('Api Key resolver', () => {
return testAPIKey(apiKey).expect(500)
})
})
describe('get api keys', () => {
before(async () => {
name = 'test-get-api-keys'
query = `
mutation {
generateApiKey(input: {
name: "${name}"
expiresAt: "${new Date(
Date.now() + 1000 * 60 * 60 * 24
).toISOString()}"
}) {
... on GenerateApiKeySuccess {
apiKey {
id
key
}
}
... on GenerateApiKeyError {
errorCodes
}
}
}
`
const response = await graphqlRequest(query, authToken)
apiKeyId = response.body.data.generateApiKey.apiKey.id
})
it('should get api keys', async () => {
query = `
query {
apiKeys {
... on ApiKeysSuccess {
apiKeys {
id
name
expiresAt
usedAt
}
}
... on ApiKeysError {
errorCodes
}
}
}
`
const response = await graphqlRequest(query, authToken).expect(200)
expect(response.body.data.apiKeys.apiKeys).to.be.an('array')
expect(response.body.data.apiKeys.apiKeys[0].id).to.eql(apiKeyId)
expect(response.body.data.apiKeys.apiKeys[0].name).to.eql(name)
expect(response.body.data.apiKeys.apiKeys[0].usedAt).to.be.null
})
})
})