Skip to content

Commit

Permalink
test: test all bounty api request
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams committed Oct 2, 2024
1 parent 21b5194 commit df0b70b
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/network/postBounty/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { getTribeUserDetails, getWorkspace, postBountyData } from '..'
import { TRIBE_BASE_URL } from '../../../utils/constants/index'
import { api } from '../../api'

// Successfully retrieves user details with a valid pubkey
it('should return user details when given a valid pubkey', async () => {
const mockPubkey = 'validPubkey123'
const mockResponse = {

Check failure on line 8 in src/network/postBounty/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Expected blank line before this statement
id: 1,
uuid: 'uuid-123',
unique_name: 'uniqueName',
owner_alias: 'ownerAlias',
}

jest.spyOn(api, 'get').mockResolvedValue(mockResponse)

const result = await getTribeUserDetails(mockPubkey)

expect(result).toEqual(mockResponse)
expect(api).toHaveBeenCalledWith(`${TRIBE_BASE_URL}/person/${mockPubkey}`, {

Check failure on line 20 in src/network/postBounty/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Expected blank line before this statement
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
})

// Successfully retrieves a list of workspaces for a valid user ID
it('should return a list of workspaces when given a valid user ID', async () => {
const mockResponse = [
{ name: 'Workspace1', uuid: '123' },
{ name: 'Workspace2', uuid: '456' },
]
jest.spyOn(api, 'get').mockResolvedValue(mockResponse)

Check failure on line 34 in src/network/postBounty/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Expected blank line before this statement

const result = await getWorkspace(1)

expect(result).toEqual(mockResponse)
expect(api).toHaveBeenCalledWith('https://community.sphinx.chat/workspaces/user/1', {

Check failure on line 39 in src/network/postBounty/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Expected blank line before this statement
headers: { 'Content-Type': 'application/json' },
method: 'GET',
})
})

// Successfully posts a valid BountyPayload and receives a positive response
it('should post valid BountyPayload and receive positive response', async () => {
const payload = {
type: 'bug',
amount: 100,
workspace_uuid: '1234-5678',
jwt_token: 'valid_token',
ref_id: 'ref123',
node_data: {},
}

const mockResponse = { status: 200, data: { success: true } }
jest.spyOn(api, 'post').mockResolvedValue(mockResponse)

Check failure on line 57 in src/network/postBounty/__tests__/index.ts

View workflow job for this annotation

GitHub Actions / eslint-run

Expected blank line before this statement

const response = await postBountyData(payload)

expect(api.post).toHaveBeenCalledWith('/bounty', JSON.stringify(payload))
expect(response).toEqual(mockResponse)
})

0 comments on commit df0b70b

Please sign in to comment.