Skip to content

Commit

Permalink
Release 0.2.2
Browse files Browse the repository at this point in the history
Release 0.2.2
  • Loading branch information
SpertsyanKM authored May 12, 2023
2 parents b1e3fa6 + e68a4d7 commit 11d37c7
Show file tree
Hide file tree
Showing 29 changed files with 2,236 additions and 417 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/integration_tests.yml
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
8 changes: 4 additions & 4 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '20.x'

- name: Cache NPM # leverage npm cache on repeated workflow runs if package.json didn't change
uses: actions/cache@v1
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '20.x'

- name: Cache NPM # leverage npm cache on repeated workflow runs if package.json didn't change
uses: actions/cache@v1
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
node-version: '20.x'

- name: Cache NPM
uses: actions/cache@v1
Expand All @@ -84,4 +84,4 @@ jobs:
run: yarn

- name: Run tests
run: yarn test
run: yarn test
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup node for publishing
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Publish to npm
Expand Down
15 changes: 14 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ def update_package_json(new_version)
update_file(path, regex, result_value)
end

def update_aegis_url_in_tests(url)
path = Dir['../**/__integrationTests__/constants.ts'].first
regex = /\<paste aegis link here\>/

update_file(path, regex, url)
end

def update_file(path, regex, result_value)
file = File.read(path)
new_content = file.gsub(regex, result_value)
Expand All @@ -35,4 +42,10 @@ platform :mac do

update_package_json(new_version)
end
end

lane :setAegisUrl do |options|
path = options[:url]

update_aegis_url_in_tests(path)
end
end
8 changes: 8 additions & 0 deletions fastlane/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do



### mac setAegisUrl

```sh
[bundle exec] fastlane mac setAegisUrl
```



----

This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
Expand Down
2 changes: 1 addition & 1 deletion fastlane/report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



<testcase classname="fastlane.lanes" name="0: default_platform" time="0.119996">
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.123619">

</testcase>

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@qonversion/web-sdk",
"title": "Qonversion Web SDK",
"version": "0.2.1",
"version": "0.2.2",
"description": "Qonversion provides full in-app purchases infrastructure, so you do not need to build your own server for receipt validation. Implement in-app subscriptions, validate user receipts, check subscription status, and provide access to your app features and content using our Stripe wrapper, StoreKit wrapper and Google Play Billing wrapper.",
"main": "sdk/build/index.js",
"types": "sdk/build/index.d.ts",
Expand All @@ -10,7 +10,8 @@
],
"scripts": {
"build": "yarn tsc",
"test": "jest",
"test": "jest ./sdk/src/__tests__",
"integrationTests": "jest ./sdk/src/__integrationTests__",
"lint": "eslint . --max-warnings=0"
},
"repository": {
Expand Down Expand Up @@ -38,13 +39,14 @@
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@types/jest": "^27.5.1",
"@types/jest": "^29.4.0",
"@typescript-eslint/eslint-plugin": "^5.28.0",
"@typescript-eslint/parser": "^5.28.0",
"babel-jest": "^28.1.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^28.1.0",
"jest": "^29.4.2",
"ts-jest": "^29.1.0",
"typescript": "^4.7.3"
},
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion sdk/src/QonversionConfigBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {QonversionErrorCode} from './exception/QonversionErrorCode';
import {Environment} from './dto/Environment';
import {LogLevel} from './dto/LogLevel';
import {LoggerConfig, NetworkConfig, PrimaryConfig, QonversionConfig} from './types';
import {API_URL} from './internal/network';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../../package.json');
Expand Down Expand Up @@ -88,12 +89,13 @@ export class QonversionConfigBuilder {

const networkConfig: NetworkConfig = {
canSendRequests: true,
apiUrl: API_URL,
};

return {
primaryConfig,
loggerConfig,
networkConfig,
};
}
};
}
63 changes: 63 additions & 0 deletions sdk/src/__integrationTests__/apiV3/EntitlementsService.test.ts
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 sdk/src/__integrationTests__/apiV3/IdentityService.test.ts
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);
},
);
});
});
});
Loading

0 comments on commit 11d37c7

Please sign in to comment.