forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We need a way to initialize an account's "plan" with information about the product the user has selected and an billing ID used by the billing system. Add this and more tests that demonstrate how it is expected to be used.
- Loading branch information
Showing
6 changed files
with
134 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
import * as API from '../../src/types.js' | ||
|
||
const account = 'did:mailto:example.com:alice' | ||
const billingID = 'stripe:abc123' | ||
const product = 'did:web:free.web3.storage' | ||
|
||
/** | ||
* @type {API.Tests} | ||
*/ | ||
export const test = { | ||
'should persist plans': async (assert, context) => { | ||
'can initialize a customer': async (assert, context) => { | ||
const storage = context.plansStorage | ||
|
||
const initializeResult = await storage.initialize(account, billingID, product) | ||
|
||
assert.ok(initializeResult.ok) | ||
|
||
const getResult = await storage.get(account) | ||
assert.equal(getResult.ok?.product, product) | ||
}, | ||
|
||
'should not allow plans to be updated for uninitialized customers': async (assert, context) => { | ||
const storage = context.plansStorage | ||
|
||
const account = 'did:mailto:example.com:alice' | ||
const product = 'did:web:free.web3.storage' | ||
const setResult = await storage.set(account, product) | ||
|
||
assert.ok(setResult.ok) | ||
assert.ok(setResult.error) | ||
assert.equal(setResult.error?.name, 'CustomerNotFound') | ||
}, | ||
|
||
'should allow plans to be updated for initialized customers': async (assert, context) => { | ||
const storage = context.plansStorage | ||
|
||
const initializeResult = await storage.initialize(account, billingID, product) | ||
|
||
assert.ok(initializeResult.ok) | ||
|
||
const getResult = await storage.get(account) | ||
assert.equal(getResult.ok?.product, product) | ||
|
||
const newProduct = 'did:web:expensive.web3.storage' | ||
|
||
const setResult = await storage.set(account, newProduct) | ||
|
||
assert.ok(setResult.ok) | ||
|
||
const newGetResult = await storage.get(account) | ||
assert.equal(newGetResult.ok?.product, newProduct) | ||
}, | ||
} |
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