# cordova-plugin-purchase-mock

> A mock implementation of the `store` object provided by [cordova-plugin-purchase](https://github.com/j3k0/cordova-plugin-purchase)

Latest version **1.1.0** (published 2022-11-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install cordova-plugin-purchase-mock
pnpm add cordova-plugin-purchase-mock
yarn add cordova-plugin-purchase-mock
bun add cordova-plugin-purchase-mock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-11-24 |
| First published | 2022-10-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | korynunn |

## Links

- npm: https://www.npmjs.com/package/cordova-plugin-purchase-mock
- npm.io page: https://npm.io/package/cordova-plugin-purchase-mock

## Dependencies (1)

- [cordova-plugin-purchase](https://npm.io/package/cordova-plugin-purchase.md) ^11.0.0

## Recent versions

- 1.1.0 (latest) — 2022-11-24
- 1.0.0 — 2022-10-06

## README

# cordova-plugin-purchase-mock

A mock implementation of the `store` object provided by [cordova-plugin-purchase](https://github.com/j3k0/cordova-plugin-purchase)

## Why

So you can write tests that use all the unmocked business logic in your code.

## Warning

I've only implemented the bare-minimum that I needed for my tests, you almost definitelly will hit limitations.
I encourage you to send PR's to flesh out this mock.

## Usage

```js
const createMockStore = require('cordova-plugin-purchase-mock');

test('Check that our integration with cordova-plugin-purchase works good', t => {
  const mockStore = createMockStore(

    // Parameter 1: Options
    {

      // Use this hook to tell the mock if the native purchase happend or not.
      // returning a transaction results in an "approved" event
      // returning null results in a "cancelled" event
      // The transaction will be set on product.transaction.
      onOrder: product => ({
        type: 'android-playstore',
        developerPayload: undefined,
        id: 'foo',
        purchaseToken: 'fakeToken',
        receipt: JSON.stringify({
            'orderId':'foo',
            'packageName':'app.gritlife.mobile',
            'purchaseTime': Date.now(),
            'purchaseState': 0,
            'purchaseToken':'fakeToken'
        }),
        signature: 'fakeSignature',
      })
    },

    // Parameter 1: "Remove" products
    // These are the products to be "loaded" from the payment provider when you call store.refresh()
    {
      'test_product_id': {
        id: 'test_product_id',
        price: '$0.99USD',
        title: 'Test',
        description: 'test product'
      }
    }
  );

  // Mock the inAppPurchase store
  app.window.store = mockStore;

  // Use the store..
});
```

---
_Source: https://npm.io/package/cordova-plugin-purchase-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
