-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setup on a null appuserid and adds listener removal methods (#39)
* fixes null appuserid * adds removelisteners methods * PR comments * Jest and some sample tests (#41) * add tests * test * makes tests its own job * removes setup job and changes setup script * changes remove listener methods to receive an instance * removes running tests in the ios flow * fixes tests * adds tests for other listeners * PR comments * updates android image
- Loading branch information
Showing
11 changed files
with
6,445 additions
and
433 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 |
---|---|---|
@@ -1,68 +1,74 @@ | ||
version: 2 | ||
jobs: | ||
setup: | ||
working_directory: ~/react-native-purchases | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- run: yarn run setup | ||
android: | ||
working_directory: ~/react-native-purchases | ||
docker: | ||
- image: circleci/android:api-27-node8-alpha | ||
steps: | ||
- checkout | ||
- run: | ||
name: yarn run setup | ||
command: yarn run setup | ||
- run: | ||
name: Android compiles | ||
command: ./gradlew build | ||
working_directory: example/android | ||
ios: | ||
macos: | ||
xcode: "9.0" | ||
working_directory: ~/react-native-purchases | ||
# use a --login shell so our "set Ruby version" command gets picked up for later steps | ||
shell: /bin/bash --login -o pipefail | ||
steps: | ||
- checkout | ||
- run: | ||
name: set Ruby version | ||
command: echo "ruby-2.4" > ~/.ruby-version | ||
- run: yarn run setup | ||
- restore_cache: | ||
key: bundle-v1-{{ checksum "example/ios/Gemfile.lock" }}-{{ arch }} | ||
- run: | ||
command: bundle install | ||
working_directory: example/ios | ||
tests: | ||
working_directory: ~/react-native-purchases | ||
docker: | ||
- image: circleci/node:8 | ||
steps: | ||
- checkout | ||
- run: yarn | ||
- run: | ||
name: Tests | ||
command: yarn test | ||
android: | ||
working_directory: ~/react-native-purchases | ||
docker: | ||
- image: circleci/android:api-28-node8-alpha | ||
steps: | ||
- checkout | ||
- run: | ||
name: yarn run setup.example | ||
command: yarn run setup.example | ||
- run: | ||
name: Android compiles | ||
command: ./gradlew build | ||
working_directory: example/android | ||
ios: | ||
macos: | ||
xcode: "9.0" | ||
working_directory: ~/react-native-purchases | ||
# use a --login shell so our "set Ruby version" command gets picked up for later steps | ||
shell: /bin/bash --login -o pipefail | ||
steps: | ||
- checkout | ||
- run: | ||
name: set Ruby version | ||
command: echo "ruby-2.4" > ~/.ruby-version | ||
- run: yarn run setup.example | ||
- restore_cache: | ||
key: bundle-v1-{{ checksum "example/ios/Gemfile.lock" }}-{{ arch }} | ||
- run: | ||
command: bundle install | ||
working_directory: example/ios | ||
|
||
- save_cache: | ||
key: bundle-v1-{{ checksum "example/ios/Gemfile.lock" }}-{{ arch }} | ||
paths: | ||
- vendor/bundle | ||
- save_cache: | ||
key: bundle-v1-{{ checksum "example/ios/Gemfile.lock" }}-{{ arch }} | ||
paths: | ||
- vendor/bundle | ||
|
||
- run: | ||
command: bundle exec fastlane scan --scheme ReactNativeSample | ||
working_directory: example/ios | ||
- run: | ||
command: bundle exec fastlane scan --scheme ReactNativeSample | ||
working_directory: example/ios | ||
|
||
- run: | ||
name: set up test results | ||
working_directory: example/ios | ||
when: always | ||
command: | | ||
mkdir -p test-results/fastlane test-results/xcode | ||
mv fastlane/report.xml test-results/fastlane | ||
mv fastlane/test_output/report.junit test-results/xcode/junit.xml | ||
- store_test_results: | ||
path: example/ios/test-results | ||
- run: | ||
name: set up test results | ||
working_directory: example/ios | ||
when: always | ||
command: | | ||
mkdir -p test-results/fastlane test-results/xcode | ||
mv fastlane/report.xml test-results/fastlane | ||
mv fastlane/test_output/report.junit test-results/xcode/junit.xml | ||
- store_test_results: | ||
path: example/ios/test-results | ||
|
||
- store_artifacts: | ||
path: example/ios/test-results | ||
- store_artifacts: | ||
path: example/ios/test-results | ||
workflows: | ||
version: 2 | ||
node-android-ios: | ||
jobs: | ||
- android | ||
- ios | ||
tests: | ||
jobs: | ||
- tests |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
describe("Purchases", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
jest.mock("NativeEventEmitter"); | ||
}); | ||
|
||
const purchaserInfoStub = {"allExpirationDates":{"onetime_purchase":null,"consumable":null,"annual_freetrial":"2019-01-23T22:34:21Z","onemonth_freetrial":"2019-01-19T01:41:06Z"},"activeSubscriptions":["annual_freetrial"],"expirationsForActiveEntitlements":{"pro":null},"activeEntitlements":["pro"],"allPurchasedProductIdentifiers":["onetime_purchase","consumable","annual_freetrial","onemonth_freetrial"],"latestExpirationDate":"2019-01-23T22:34:21Z"}; | ||
|
||
it("isUTCDateStringFuture returns true when a date is in the future", () => { | ||
const { isUTCDateStringFuture } = require("../index"); | ||
const dateAhead = new Date(); | ||
dateAhead.setDate(dateAhead.getDate() + 2); | ||
|
||
expect(isUTCDateStringFuture(dateAhead.toUTCString())).toEqual(true); | ||
}); | ||
|
||
it("addPurchaseListener correctly saves listeners", () => { | ||
const listener = jest.fn(); | ||
const Purchases = require("../index").default; | ||
|
||
Purchases.addPurchaseListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
productIdentifier: "test.product.bla", | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-PurchaseCompleted", eventInfo); | ||
|
||
expect(listener).toEqual(expect.any(Function)); | ||
expect(listener).toHaveBeenCalledWith( | ||
eventInfo.productIdentifier, | ||
eventInfo.purchaserInfo, | ||
eventInfo.error | ||
); | ||
}); | ||
|
||
it("removePurchaseListener correctly removes a listener", () => { | ||
const Purchases = require("../index").default; | ||
const listener = jest.fn(); | ||
Purchases.addPurchaseListener(listener); | ||
Purchases.removePurchaseListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
productIdentifier: "test.product.bla", | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-PurchaseCompleted", eventInfo); | ||
|
||
expect(listener).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it("addRestoreTransactionsListener correctly saves listeners", () => { | ||
const listener = jest.fn(); | ||
const Purchases = require("../index").default; | ||
|
||
Purchases.addRestoreTransactionsListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-RestoredTransactions", eventInfo); | ||
|
||
expect(listener).toEqual(expect.any(Function)); | ||
expect(listener).toHaveBeenCalledWith( | ||
eventInfo.purchaserInfo, | ||
eventInfo.error | ||
); | ||
}); | ||
|
||
it("removeRestoreTransactionsListener correctly removes a listener", () => { | ||
const Purchases = require("../index").default; | ||
const listener = jest.fn(); | ||
Purchases.addRestoreTransactionsListener(listener); | ||
Purchases.removeRestoreTransactionsListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-RestoredTransactions", eventInfo); | ||
|
||
expect(listener).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it("addPurchaserInfoUpdateListener correctly saves listeners", () => { | ||
const listener = jest.fn(); | ||
const Purchases = require("../index").default; | ||
|
||
Purchases.addPurchaserInfoUpdateListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-PurchaserInfoUpdated", eventInfo); | ||
|
||
expect(listener).toEqual(expect.any(Function)); | ||
expect(listener).toHaveBeenCalledWith( | ||
eventInfo.purchaserInfo, | ||
eventInfo.error | ||
); | ||
}); | ||
|
||
it("removePurchaserInfoUpdateListener correctly removes a listener", () => { | ||
const Purchases = require("../index").default; | ||
const listener = jest.fn(); | ||
Purchases.addPurchaserInfoUpdateListener(listener); | ||
Purchases.removePurchaserInfoUpdateListener(listener); | ||
|
||
const nativeEmitter = new NativeEventEmitter(); | ||
|
||
const eventInfo = { | ||
purchaserInfo: purchaserInfoStub, | ||
error: null, | ||
}; | ||
|
||
nativeEmitter.emit("Purchases-PurchaserInfoUpdated", eventInfo); | ||
|
||
expect(listener).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
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
Oops, something went wrong.