Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanjakl committed May 10, 2024
1 parent 6dcc348 commit 8760400
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ The `stripe-products` module contains a custom API route (`'/api/v1/stripe-produ

## TODOs (Limitations)

- add tests
- archive products when they are not included in the API request payload
- fix disappering `stripeProductObject` and `stripePriceObject` data when moved between `draft` and `published` modes and vice versa
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ module.exports = {

// Set archived status based on product's active status
docToUpdate.archived = !product.active;

docToUpdate.updatedAt = new Date();

await self.apos.stripeProduct.update(req, docToUpdate);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stepanjakl/apostrophe-stripe-products",
"version": "0.0.3",
"version": "0.0.4",
"description": "Stripe Products For ApostropheCMS",
"keywords": [
"apostrophe",
Expand Down Expand Up @@ -34,10 +34,10 @@
"eslint-plugin-mocha": "^10.4.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.25.0",
"eslint-plugin-vue": "^9.26.0",
"mocha": "^10.4.0",
"read-only-field": "npm:@stepanjakl/apostrophe-read-only-field@latest",
"stripe": "^15.3.0",
"stripe": "^15.6.0",
"stylelint": "^15.x.x",
"stylelint-config-apostrophe": "^3.0.2"
},
Expand Down
36 changes: 16 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('Apostrophe - Stripe Products Integration Tests', function () {
user.title = 'admin';
user.username = 'admin';
user.password = 'admin';
user.email = 'ad@min.com';
user.email = 'admin@example.com';
user.role = 'admin';

await apos.user.insert(apos.task.getReq(), user);
});

it('should log in as admin and make a GET request to establish CSRF cookie', async function() {
it('should log in as admin and establish a CSRF cookie with a GET request', async function() {
jar = apos.http.jar();

let page = await apos.http.get('/', { jar });
Expand Down Expand Up @@ -99,26 +99,22 @@ describe('Apostrophe - Stripe Products Integration Tests', function () {
assert.strictEqual(response.productList.length > 0, true);
});

/* it('should send request to webhook endpoint and save the completed checkout session to the database', async function () {
it('should retrieve products via REST API using a GET request', async function () {
let response;

await apos.http.post('/api/v1/stripe/checkout/webhook', {
headers: {
'stripe-signature': 't=1711059559,v1=9dd216ac7ffc2d07d3edd4b4de4a67200705c52f435e92bc3b21a605f3af91af,v0=4251a0f2bbd73dd1622bb01aedb334cab148be2a84bb3b1daea4af931e0172e2'
},
body: {
id: 'evt_xyz',
object: 'event'
}
}).catch(error => {
try {
response = await apos.http.get('/api/v1/stripe-products/product', {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
jar
});
} catch (error) {
console.error('An error occurred:', error);
throw error;
});
const sessionDoc = await apos.stripeCheckoutSession.find(apos.task.getReq(), {
slug: 'cs_xyz',
aposMode: 'published'
}).toObject();
}

assert(sessionDoc);
}); */
assert.strictEqual(response.results.length > 0, true);
});
});

0 comments on commit 8760400

Please sign in to comment.