Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
SpertsyanKM authored Aug 14, 2023
2 parents b47384b + 9674156 commit 52275e9
Show file tree
Hide file tree
Showing 30 changed files with 533 additions and 161 deletions.
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.123619">
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.070813">

</testcase>

Expand Down
2 changes: 1 addition & 1 deletion 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.2",
"version": "1.0.0",
"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 Down
40 changes: 30 additions & 10 deletions sdk/src/UserPropertiesBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {UserProperty} from './dto/UserProperty';
import {UserPropertyKey} from './dto/UserPropertyKey';

/**
* This builder class can be used to generate a map of user properties
Expand All @@ -17,18 +17,18 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setName(name: string): UserPropertiesBuilder {
this.properties[UserProperty.Name] = name;
this.properties[UserPropertyKey.Name] = name;
return this;
}

/**
* Set custom user id. It can be an identifier used on your backend
* to link the current Qonversion user with your one.
* @param customUserId unique user id
* @return builder instance for chain calls
*/
setCustomUserId(customUserId: string): UserPropertiesBuilder {
this.properties[UserProperty.CustomUserId] = customUserId;
this.properties[UserPropertyKey.CustomUserId] = customUserId;
return this;
}

Expand All @@ -38,7 +38,7 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setEmail(email: string): UserPropertiesBuilder {
this.properties[UserProperty.Email] = email;
this.properties[UserPropertyKey.Email] = email;
return this;
}

Expand All @@ -48,7 +48,7 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setKochavaDeviceId(deviceId: string): UserPropertiesBuilder {
this.properties[UserProperty.KochavaDeviceId] = deviceId;
this.properties[UserPropertyKey.KochavaDeviceId] = deviceId;
return this;
}

Expand All @@ -59,7 +59,7 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setAppsFlyerUserId(userId: string): UserPropertiesBuilder {
this.properties[UserProperty.AppsFlyerUserId] = userId;
this.properties[UserPropertyKey.AppsFlyerUserId] = userId;
return this;
}

Expand All @@ -69,7 +69,7 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setAdjustAdvertisingId(advertisingId: string): UserPropertiesBuilder {
this.properties[UserProperty.AdjustAdId] = advertisingId;
this.properties[UserPropertyKey.AdjustAdId] = advertisingId;
return this;
}

Expand All @@ -79,7 +79,7 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setFacebookAttribution(facebookAttribution: string): UserPropertiesBuilder {
this.properties[UserProperty.FacebookAttribution] = facebookAttribution;
this.properties[UserPropertyKey.FacebookAttribution] = facebookAttribution;
return this;
}

Expand All @@ -89,7 +89,27 @@ export class UserPropertiesBuilder {
* @return builder instance for chain calls
*/
setFirebaseAppInstanceId(firebaseAppInstanceId: string): UserPropertiesBuilder {
this.properties[UserProperty.FirebaseAppInstanceId] = firebaseAppInstanceId;
this.properties[UserPropertyKey.FirebaseAppInstanceId] = firebaseAppInstanceId;
return this;
}

/**
* Set Android app set id.
* @param appSetId app set id
* @return builder instance for chain calls
*/
setAppSetId(appSetId: string): UserPropertiesBuilder {
this.properties[UserPropertyKey.AppSetId] = appSetId;
return this;
}

/**
* Set iOS advertising id.
* @param advertisingId advertising id
* @return builder instance for chain calls
*/
setAdvertisingId(advertisingId: string): UserPropertiesBuilder {
this.properties[UserPropertyKey.AdvertisingId] = advertisingId;
return this;
}

Expand Down
29 changes: 24 additions & 5 deletions sdk/src/__tests__/internal/QonversionInternal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import Qonversion, {
LogLevel,
PurchaseCoreData,
StripeStoreData,
UserProperty,
UserPropertyKey,
UserPurchase,
} from '../../index';
import {UserPropertiesController} from '../../internal/userProperties';
import {UserController} from '../../internal/user';
import {EntitlementsController, EntitlementsControllerImpl} from '../../internal/entitlements';
import {PurchasesController, PurchasesControllerImpl} from '../../internal/purchases';
import {Logger} from '../../internal/logger';
import {API_URL} from '../../internal/network';
import {UserProperties} from '../../dto/UserProperties';
import {UserProperty} from '../../dto/UserProperty';

jest.mock('../../internal/di/DependenciesAssembly', () => {
const originalModule = jest.requireActual('../../internal/di/DependenciesAssembly');
Expand All @@ -41,6 +44,7 @@ beforeEach(() => {
};
networkConfig = {
canSendRequests: true,
apiUrl: API_URL,
};
loggerConfig = {
logTag: '',
Expand Down Expand Up @@ -190,7 +194,7 @@ describe('UserPropertiesController usage tests', () => {

test('setUserProperty', () => {
// given
const key = UserProperty.AppsFlyerUserId;
const key = UserPropertyKey.AppsFlyerUserId;
const value = 'property_value';
userPropertyController.setProperty = jest.fn();

Expand Down Expand Up @@ -218,21 +222,35 @@ describe('UserPropertiesController usage tests', () => {
expect(userPropertyController.setProperties).toBeCalledWith(properties);
expect(logger.verbose).toBeCalledWith('setUserProperties() call');
});

test('userProperties', async () => {
// given
const response = new UserProperties([new UserProperty('testKey', 'testValue')]);
userPropertyController.getProperties = jest.fn(() => Promise.resolve(response));

// when
const res = await qonversionInternal.userProperties();

// then
expect(res).toEqual(response);
expect(userPropertyController.getProperties).toBeCalledWith();
expect(logger.verbose).toBeCalledWith('userProperties() call');
});
});

describe('EntitlementsController usage tests', () => {
test('getEntitlements', () => {
test('entitlements', () => {
// given
const promiseReturned = new Promise<Entitlement[]>(() => []);
entitlementsController.getEntitlements = jest.fn(async () => promiseReturned);

// when
const res = qonversionInternal.getEntitlements();
const res = qonversionInternal.entitlements();

// then
expect(res).toStrictEqual(promiseReturned);
expect(entitlementsController.getEntitlements).toBeCalled();
expect(logger.verbose).toBeCalledWith('getEntitlements() call');
expect(logger.verbose).toBeCalledWith('entitlements() call');
});
});

Expand All @@ -248,6 +266,7 @@ describe('PurchasesController usage tests', () => {
productId: 'test product id',
subscriptionId: 'test subscription id',
},
userId: 'Qon_test_user_id'
};
const requestData: PurchaseCoreData & StripeStoreData = {
currency: 'USD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
ApiInteractor,
RequestConfigurator,
NetworkRequest,
NetworkResponseError,
NetworkResponseSuccess
ApiResponseError,
ApiResponseSuccess
} from '../../../internal/network';
import {
Entitlement,
Expand Down Expand Up @@ -45,14 +45,14 @@ const apiPayload: EntitlementsResponse = {
data: [apiEntitlement],
object: 'list'
};
const testSuccessfulResponse: NetworkResponseSuccess<EntitlementsResponse> = {
const testSuccessfulResponse: ApiResponseSuccess<EntitlementsResponse> = {
code: 200,
data: apiPayload,
isSuccess: true
};
const testErrorCode = 500;
const testErrorMessage = 'Test error message';
const testErrorResponse: NetworkResponseError = {
const testErrorResponse: ApiResponseError = {
code: testErrorCode,
apiCode: '',
message: testErrorMessage,
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('getEntitlements tests', function () {

test('user does not exist', async () => {
// given
const testUserNotFoundResponse: NetworkResponseError = {
const testUserNotFoundResponse: ApiResponseError = {
code: HTTP_CODE_NOT_FOUND,
apiCode: '',
message: testErrorMessage,
Expand Down
10 changes: 5 additions & 5 deletions sdk/src/__tests__/internal/network/ApiInteractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
ExponentialDelayCalculator,
NetworkClientImpl,
NetworkRequest,
NetworkResponseError,
NetworkResponseSuccess,
ApiResponseError,
ApiResponseSuccess,
NetworkRetryConfig,
RawNetworkResponse,
RequestType,
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('execute tests', () => {
code: testResponseCode,
payload: testPayload,
};
let errorResponse: NetworkResponseError = {
let errorResponse: ApiResponseError = {
apiCode: '',
code: 0,
message: '',
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('execute tests', () => {

test('execute with successful response', async () => {
// given
const expResponse: NetworkResponseSuccess<typeof testPayload> = {
const expResponse: ApiResponseSuccess<typeof testPayload> = {
code: testResponseCode,
data: testPayload,
isSuccess: true,
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('getErrorResponse tests', () => {
code: testErrorCode,
payload: {error: apiError},
};
const expResult: NetworkResponseError = {
const expResult: ApiResponseError = {
apiCode: testErrorApiCode,
code: testErrorCode,
message: testErrorMessage,
Expand Down
30 changes: 21 additions & 9 deletions sdk/src/__tests__/internal/network/RequestConfigurator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,34 @@ describe('RequestConfigurator tests', () => {
expect(request).toStrictEqual(expResult);
});

test('user properties request', () => {
test('user properties send request', () => {
// given
const properties = {a: 'a', b: 'b'};
const properties = [{key: 'a', value: 'a'}, {key: 'b', value: 'b'}];
const expResult: NetworkRequest = {
headers: testHeaders,
type: RequestType.POST,
url: testBaseUrl + '/' + ApiEndpoint.Properties,
body: {
access_token: testProjectKey,
q_uid: testUserId,
properties,
}
url: testBaseUrl + '/' + ApiEndpoint.Users + '/' + testUserId + '/' + ApiEndpoint.Properties,
body: properties,
};

// when
const request = requestConfigurator.configureUserPropertiesSendRequest(testUserId, properties);

// then
expect(request).toStrictEqual(expResult);
});

test('user properties get request', () => {
// given
const expResult: NetworkRequest = {
headers: testHeaders,
type: RequestType.GET,
url: testBaseUrl + '/' + ApiEndpoint.Users + '/' + testUserId + '/' + ApiEndpoint.Properties,
body: undefined,
};

// when
const request = requestConfigurator.configureUserPropertiesRequest(properties);
const request = requestConfigurator.configureUserPropertiesGetRequest(testUserId);

// then
expect(request).toStrictEqual(expResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const testUserPurchase: UserPurchase = {
productId: 'test product id',
subscriptionId: 'test subscription id'
},
userId: testUserId,
};

const testStripePurchaseData: PurchaseCoreData & StripeStoreData = {
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/__tests__/internal/purchases/PurchasesService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
ApiInteractor,
RequestConfigurator,
NetworkRequest,
NetworkResponseError,
NetworkResponseSuccess
ApiResponseError,
ApiResponseSuccess
} from '../../../internal/network';
import {
PurchaseCoreData,
Expand All @@ -23,20 +23,21 @@ const apiPurchase: UserPurchaseApi = {
currency: 'USD',
price: '10',
purchased: 3243523432,
userId: testUserId,
stripe_store_data: {
product_id: 'test product id',
subscription_id: 'test subscription id'
},
};

const testSuccessfulResponse: NetworkResponseSuccess<UserPurchaseApi> = {
const testSuccessfulResponse: ApiResponseSuccess<UserPurchaseApi> = {
code: 200,
data: apiPurchase,
isSuccess: true
};
const testErrorCode = 500;
const testErrorMessage = 'Test error message';
const testErrorResponse: NetworkResponseError = {
const testErrorResponse: ApiResponseError = {
code: testErrorCode,
apiCode: '',
message: testErrorMessage,
Expand All @@ -47,6 +48,7 @@ const expRes: UserPurchase = {
currency: 'USD',
price: '10',
purchased: 3243523432,
userId: testUserId,
stripeStoreData: {
productId: 'test product id',
subscriptionId: 'test subscription id'
Expand Down
Loading

0 comments on commit 52275e9

Please sign in to comment.