Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
69 changes: 69 additions & 0 deletions src/api/endpoints/addPermission.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { ApiAddPermissionParams, callApiAddPermission } from './addPermission'
import { ApiEndpoint, ApiMessageResult, ChainNetwork, ExternalWalletType } from '../../models'
import * as helpers from '../helpers'
import OreIdContext from '../../core/IOreidContext'
import { createOreIdContext } from '../../test-utils'

function isApiAddPermissionParams(obj: any): obj is ApiAddPermissionParams {
return (
'account' in obj &&
obj.account === 'account value' &&
'chainAccount' in obj &&
obj.chainAccount === 'chainAccount value' &&
'chainNetwork' in obj &&
obj.chainNetwork === 'algo_beta' &&
'parentPermission' in obj &&
obj.parentPermission === 'geolocation' &&
'permission' in obj &&
obj.permission === 'geolocation' &&
'provider' in obj &&
obj.provider === 'algosigner' &&
'publicKey' in obj &&
obj.publicKey === 'publicKey value'
)
}

const aapp: ApiAddPermissionParams = {
account: 'account value',
chainAccount: 'chainAccount value',
chainNetwork: ChainNetwork.AlgoBeta,
parentPermission: 'geolocation',
permission: 'geolocation',
provider: ExternalWalletType.AlgoSigner,
publicKey: 'publicKey value',
}

describe('Api Add Permission Params type', () => {
test('type can be instantiated', () => {
expect(isApiAddPermissionParams(aapp)).toBeTruthy()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These instantiation tests aren't needed, they don't any functionality

})
})

let oreIdContext: OreIdContext

beforeEach(() => {
oreIdContext = createOreIdContext()
})

afterEach(() => {
jest.clearAllMocks()
})

describe('Add API permission', () => {
test('should return a valid response', async () => {
const tpSpyKeyOrToken = jest.spyOn(helpers, 'assertHasApiKeyOrAccessToken')
const tpSpyReqdParams = jest.spyOn(helpers, 'assertParamsHaveRequiredValues')
const tpSpyApiCall = jest.spyOn(oreIdContext, 'callOreIdApi')
const resultValue: ApiMessageResult = { success: 'true' }
tpSpyApiCall.mockReturnValue(resultValue as Promise<ApiMessageResult>)
expect(tpSpyKeyOrToken).not.toBeCalled()
expect(tpSpyReqdParams).not.toBeCalled()
expect(tpSpyApiCall).not.toBeCalled()
const result: ApiMessageResult = await callApiAddPermission(oreIdContext, aapp)
expect(tpSpyKeyOrToken).toBeCalledWith(oreIdContext, ApiEndpoint.AddPermission)
expect(tpSpyApiCall).toBeCalled()
expect(result).toBeTruthy()
expect(result.success).toBeDefined()
expect(result.success).toEqual('true')
})
})
58 changes: 58 additions & 0 deletions src/api/endpoints/appToken.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ApiGetAppTokenParams, callApiGetAppToken } from './appToken'
import {
ApiEndpoint,
AppAccessTokenMetadata,
RequestType,
ApiKeyUsedFor,
NewAccountAppTokenParams,
AccountType,
} from '../../models'
import { assertHasApiKey } from '../helpers'
import Helpers from '../../utils/helpers'
import * as helpers from '../helpers'
import OreIdContext from '../../core/IOreidContext'
import { createOreIdContext } from '../../test-utils'

function isApiGetAppTokenParams(obj: any): obj is ApiGetAppTokenParams {
return 'appAccessTokenMetadata' in obj && typeof obj.appAccessTokenMetadata === 'object'
}

const aatmd: AppAccessTokenMetadata = {}

const agatp: ApiGetAppTokenParams = {
appAccessTokenMetadata: aatmd,
}

describe('Api Get App Token Params type', () => {
test('type can be instantiated', () => {
expect(isApiGetAppTokenParams(agatp)).toBeTruthy()
})
})

let oreIdContext: OreIdContext

beforeEach(() => {
oreIdContext = createOreIdContext()
})

afterEach(() => {
jest.clearAllMocks()
})

describe('Get app token', () => {
test('should return a valid response', async () => {
const tpNullOrEmpty = jest.spyOn(Helpers, 'isNullOrEmpty')
const tpSpyReqdParams = jest.spyOn(helpers, 'assertHasApiKey')
const tpSpyApiCall = jest.spyOn(oreIdContext, 'callOreIdApi')
const resultValue = { appAccessToken: 'appAccessToken value' }
tpSpyApiCall.mockReturnValue(resultValue as unknown as Promise<string>)
expect(tpNullOrEmpty).not.toBeCalled()
expect(tpSpyReqdParams).not.toBeCalled()
expect(tpSpyApiCall).not.toBeCalled()
const result: string = await callApiGetAppToken(oreIdContext, agatp)
expect(tpNullOrEmpty).toBeCalledWith(agatp.appAccessTokenMetadata)
expect(tpSpyReqdParams).toBeCalledWith(oreIdContext, null, ApiEndpoint.AppToken)
expect(tpSpyApiCall).toBeCalled()
expect(result).toEqual('appAccessToken value')
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/canAutoSign.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiCanAutosignTransaction } from './canAutoSign'

describe('Can auto sign', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/convertOauth.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiConvertOauthTokens } from './convertOauth'

describe('Convert OAuth', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/custodialMigrateAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiCustodialMigrateAccount } from './custodialMigrateAccount'

describe('Custodial migrate account', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/custodialNewAccount.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiCustodialNewAccount } from './custodialNewAccount'

describe('Custodial new account', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/deleteTestUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiDeleteTestUser } from './deleteTestUser'

describe('Delete test user', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/getConfig.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiGetConfig } from './getConfig'

describe('Get config', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/getUser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiGetUser } from './getUser'

describe('Get user', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/loginUserWithToken.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiLoginUserWithToken } from './loginUserWithToken'

describe('Login user with token', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/newUserWithToken.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiNewUserWithToken } from './newUserWithToken'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop the unimplemented tests, they make it hard to spot the changes


describe('New user with token', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/passwordLessSendCode.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiPasswordLessSendCode } from './passwordLessSendCode'

describe('Password-less send code', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/passwordLessVerifyCode.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiPasswordLessVerifyCode } from './passwordLessVerifyCode'

describe('Password-less verify code', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/signTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiCustodialSignTransaction } from './signTransaction'

describe('Sign transaction', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
7 changes: 7 additions & 0 deletions src/api/endpoints/updateDelayWalletSetup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { callApiUpdateDelayWalletSetup } from './updateDelayWalletSetup'

describe('Update delay wallet setup', () => {
test('should return a valid response', async () => {
expect(1).toEqual(1)
})
})
113 changes: 113 additions & 0 deletions src/api/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
assertHasAccessToken,
assertHasApiKey,
assertHasApiKeyOrAccessToken,
assertHeaderhasRequiredValues,
assertParamsHaveAtLeastOneOfValues,
assertParamsHaveOnlyOneOfValues,
assertParamsHaveRequiredValues,
extractProcessIdFromData,
} from './helpers'
import OreIdContext from '../core/IOreidContext'
import { createOreIdContext } from '../test-utils'
import { ApiKeyUsedFor } from '../models'

let oreIdContext: OreIdContext

describe('API helpers', () => {
test('should not throw an error is all required header values are present', async () => {
const obj = { test1: 'value', test2: 'value' }
const names = ['test1', 'test2']
assertHeaderhasRequiredValues(obj, names, '')
expect(1).toEqual(1)
})

test('should throw error for missing header values', async () => {
const obj = { test1: 'value' }
const names = ['test1', 'test2']
expect(() => assertHeaderhasRequiredValues(obj, names, '')).toThrow(Error)
})

test('should not throw an error if access token and api key are given', async () => {
oreIdContext = createOreIdContext()
assertHasApiKeyOrAccessToken(oreIdContext, '')
expect(1).toEqual(1)
})

test('should throw error for missing access token and api key', async () => {
oreIdContext = createOreIdContext()
delete oreIdContext.accessToken
delete oreIdContext.options.apiKey
expect(() => assertHasApiKeyOrAccessToken(oreIdContext, '')).toThrow(Error)
})

test('should not throw an error if access token is given', async () => {
oreIdContext = createOreIdContext()
assertHasAccessToken(oreIdContext, '')
expect(1).toEqual(1)
})

test('should throw error for missing access token', async () => {
oreIdContext = createOreIdContext()
delete oreIdContext.accessToken
expect(() => assertHasAccessToken(oreIdContext, '')).toThrow(Error)
})

test('should not throw an error if api key is provided', async () => {
oreIdContext = createOreIdContext()
assertHasApiKey(oreIdContext, ApiKeyUsedFor.AccountMigration, '')
expect(1).toEqual(1)
})

test('should throw error for missing api key', async () => {
oreIdContext = createOreIdContext()
delete oreIdContext.options.apiKey
expect(() => assertHasApiKey(oreIdContext, ApiKeyUsedFor.AccountMigration, '')).toThrow(Error)
})

test('should not throw an error if all paramater values are found', async () => {
const obj = { test1: 'value', test2: 'value' }
const names = ['test1', 'test2']
assertParamsHaveRequiredValues(obj, names, '')
expect(1).toEqual(1)
})

test('should throw error for missing paramater values', async () => {
const obj = { test1: 'value' }
const names = ['test1', 'test2']
expect(() => assertParamsHaveRequiredValues(obj, names, '')).toThrow(Error)
})

test('should not throw an error if at least one paramater value is found', async () => {
const obj = { test1: 'value', test2: 'value' }
const names = ['test2']
assertParamsHaveAtLeastOneOfValues(obj, names, '')
expect(1).toEqual(1)
})

test('should throw error if no required paramater values are provided', async () => {
const obj = { test1: 'value', test3: 'value', test4: 'value' }
const names = ['test2']
expect(() => assertParamsHaveAtLeastOneOfValues(obj, names, '')).toThrow(Error)
})

test('should not throw an error if only one paramater value is found from the given', async () => {
const obj = { test1: 'value', test4: 'value' }
const names = ['test1', 'test3']
assertParamsHaveOnlyOneOfValues(obj, names, '')
expect(1).toEqual(1)
})

test('should throw error if more than one required paramater values is provided', async () => {
const obj = { test1: 'value', test3: 'value', test4: 'value' }
const names = ['test1', 'test3']
expect(() => assertParamsHaveOnlyOneOfValues(obj, names, '')).toThrow(Error)
})

test('should remove processId from data', async () => {
const input = { test1: 'value', processId: 'processId' }
const { data, processId } = extractProcessIdFromData(input)
expect(data).toEqual({ test1: 'value' })
expect(processId).toEqual('processId')
})
})
Loading