-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 0.2.2
- Loading branch information
Showing
29 changed files
with
2,236 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Planned integration tests | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 3 * * *' | ||
|
||
jobs: | ||
tests: | ||
runs-on: macos-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set Aegis url | ||
run: | | ||
fastlane setAegisUrl url:${{ secrets.AEGIS_URL }} | ||
- name: Use Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Cache NPM # leverage npm cache on repeated workflow runs if package.json didn't change | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install Dependencies | ||
run: yarn | ||
|
||
- name: Tests | ||
run: | | ||
yarn integrationTests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sdk/src/__integrationTests__/apiV3/EntitlementsService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {PRIVATE_TOKEN_FOR_TESTS} from '../constants'; | ||
import {executeGrantEntitlementsRequest} from '../apiV3Utils'; | ||
import {expectQonversionErrorAsync, getCurrentTs, getDependencyAssembly} from '../utils'; | ||
import {QonversionErrorCode} from '../../exception/QonversionErrorCode'; | ||
import {API_URL} from '../../internal/network'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// noinspection JSConstantReassignment | ||
global.localStorage = { | ||
getItem: jest.fn(), | ||
}; | ||
|
||
describe('entitlements tests', function () { | ||
const dependenciesAssembly = getDependencyAssembly(); | ||
|
||
const userService = dependenciesAssembly.userService(); | ||
const entitlementsService = dependenciesAssembly.entitlementsService(); | ||
|
||
describe('GET entitlements', function () { | ||
it('get entitlements for new user', async () => { | ||
// given | ||
const userId = 'testEntitlementUserId' + Date.now(); | ||
await userService.createUser(userId); | ||
|
||
// when | ||
const res = await entitlementsService.getEntitlements(userId); | ||
|
||
// then | ||
expect(res).toEqual([]); | ||
}); | ||
|
||
it('get entitlements for user with entitlements', async () => { | ||
// given | ||
const userId = 'testEntitlementUserId' + Date.now(); | ||
await userService.createUser(userId); | ||
const entitlementId = 'Test Permission'; | ||
const expires = getCurrentTs() + 10000; | ||
const entitlementResponse = await executeGrantEntitlementsRequest(API_URL, PRIVATE_TOKEN_FOR_TESTS, userId, entitlementId, expires); | ||
const entitlement = await entitlementResponse.json(); | ||
|
||
// when | ||
const res = await entitlementsService.getEntitlements(userId); | ||
|
||
// then | ||
expect(res).toEqual([entitlement]); | ||
}); | ||
|
||
it('get entitlements for non-existent user', async () => { | ||
// given | ||
const userId = 'testNonExistentUserId' + Date.now(); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.UserNotFound, | ||
'Qonversion user not found. User id: ' + userId, | ||
async () => { | ||
await entitlementsService.getEntitlements(userId); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
130 changes: 130 additions & 0 deletions
130
sdk/src/__integrationTests__/apiV3/IdentityService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import {expectQonversionErrorAsync, getDependencyAssembly} from '../utils'; | ||
import {QonversionErrorCode} from '../../exception/QonversionErrorCode'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
// noinspection JSConstantReassignment | ||
global.localStorage = { | ||
getItem: jest.fn(), | ||
}; | ||
|
||
describe('identities tests', function () { | ||
const dependenciesAssembly = getDependencyAssembly(); | ||
|
||
const userService = dependenciesAssembly.userService(); | ||
const identityService = dependenciesAssembly.identityService(); | ||
|
||
describe('POST identities', function () { | ||
it('create correct identity', async () => { | ||
// given | ||
const identityId = 'testCorrectIdentity' + Date.now(); | ||
const userId = 'testCorrectIdentityUid' + Date.now(); | ||
await userService.createUser(userId); | ||
|
||
// when | ||
const res = await identityService.createIdentity(userId, identityId); | ||
|
||
// then | ||
expect(res).toEqual(userId); | ||
}); | ||
|
||
it('create same identity above existing', async () => { | ||
// given | ||
const identityId = 'testExistingIdentity' + Date.now(); | ||
const userId = 'testCorrectIdentityUid' + Date.now(); | ||
await userService.createUser(userId); | ||
await identityService.createIdentity(userId, identityId); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.BackendError, | ||
'Qonversion API returned an error. Response code 422, message: user already has identity', | ||
async () => { | ||
await identityService.createIdentity(userId, identityId); | ||
}, | ||
); | ||
}); | ||
|
||
it('create different identity above existing', async () => { | ||
// given | ||
const identityId = 'testExistingIdentity' + Date.now(); | ||
const userId = 'testCorrectIdentityUid' + Date.now(); | ||
await userService.createUser(userId); | ||
await identityService.createIdentity(userId, identityId); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.BackendError, | ||
'Qonversion API returned an error. Response code 422, message: user already converted', | ||
async () => { | ||
await identityService.createIdentity(userId, identityId + 'another'); | ||
}, | ||
); | ||
}); | ||
|
||
it('create identity which was already used for another user', async () => { | ||
// given | ||
const identityId = 'testExistingIdentity' + Date.now(); | ||
const identifierUserId = 'testIdentifiedUid' + Date.now(); | ||
await userService.createUser(identifierUserId); | ||
await identityService.createIdentity(identifierUserId, identityId); | ||
|
||
const nonIdentifierUserId = 'testNonIdentifiedUid' + Date.now(); | ||
await userService.createUser(nonIdentifierUserId); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.BackendError, | ||
'Qonversion API returned an error. Response code 422, message: identity already exists: it\'s linked to another user', | ||
async () => { | ||
await identityService.createIdentity(nonIdentifierUserId, identityId); | ||
}, | ||
); | ||
}); | ||
|
||
it('create identity for non-existent user', async () => { | ||
// given | ||
const identityId = 'testIdentityForNonExistentUser' + Date.now(); | ||
const nonExistentUserId = 'testNonExistentUid' + Date.now(); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.BackendError, | ||
'Qonversion API returned an error. Response code 400, message: user not found', | ||
async () => { | ||
await identityService.createIdentity(nonExistentUserId, identityId); | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
describe('GET identities', function () { | ||
it('get existing identity', async () => { | ||
// given | ||
const identityId = 'testExistingIdentity' + Date.now(); | ||
const userId = 'testExistingUid' + Date.now(); | ||
await userService.createUser(userId); | ||
await identityService.createIdentity(userId, identityId); | ||
|
||
// when | ||
const res = await identityService.obtainIdentity(identityId); | ||
|
||
// then | ||
expect(res).toEqual(userId); | ||
}); | ||
|
||
it('get non-existent identity', async () => { | ||
// given | ||
const identityId = 'testNonExistentIdentity' + Date.now(); | ||
|
||
// when and then | ||
await expectQonversionErrorAsync( | ||
QonversionErrorCode.IdentityNotFound, | ||
'User with requested identity not found. Id: ' + identityId, | ||
async () => { | ||
await identityService.obtainIdentity(identityId); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.