From a35e37a069701d32010b66b6c1a902f72a721318 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 22 Feb 2023 19:30:25 +0530 Subject: [PATCH 1/6] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad7d6625..216e9ae9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "razorpay", - "version": "2.8.5", + "version": "2.8.6", "description": "Official Node SDK for Razorpay API", "main": "dist/razorpay", "typings": "dist/razorpay", From a60c9bc052991ab8863c7131b09e6bb96d318350 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Wed, 12 Jul 2023 11:19:08 +0530 Subject: [PATCH 2/6] e2e test case items & plans --- package.json | 3 +- test_prod/razorpay.js | 8 ++++ test_prod/resources/items.spec.js | 64 +++++++++++++++++++++++++++++++ test_prod/resources/plans.spec.js | 51 ++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 test_prod/razorpay.js create mode 100644 test_prod/resources/items.spec.js create mode 100644 test_prod/resources/plans.spec.js diff --git a/package.json b/package.json index 03390d0a..642f7f1e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "build": "npm run clean && npm run build:commonjs && npm run cp-ts", "debug": "npm run build && node-debug examples/index.js", "test": "npm run build && mocha --recursive --require babel-register test/ && nyc --reporter=text mocha", - "coverage": "nyc report --reporter=text-lcov > coverage.lcov" + "coverage": "nyc report --reporter=text-lcov > coverage.lcov", + "test_prod": "npm run build && mocha --timeout 10000 --recursive --require babel-register test_prod/" }, "repository": { "type": "git", diff --git a/test_prod/razorpay.js b/test_prod/razorpay.js new file mode 100644 index 00000000..52739e22 --- /dev/null +++ b/test_prod/razorpay.js @@ -0,0 +1,8 @@ +'use strict'; + +const Razorpay = require("../dist/razorpay"); + +module.exports = new Razorpay({ + key_id: process.env.API_KEY || "", + key_secret: process.env.API_SECRET || "" +}); diff --git a/test_prod/resources/items.spec.js b/test_prod/resources/items.spec.js new file mode 100644 index 00000000..4a8ba4df --- /dev/null +++ b/test_prod/resources/items.spec.js @@ -0,0 +1,64 @@ +'use strict' + +var assert = require('assert'); +const rzpInstance = require('../razorpay') + +let itemId = null; + +describe('ITEMS', () => { + + it('item create request', (done) => { + + rzpInstance.items.create({ + "name": "Book / English August", + "description": "An indian story, Booker prize winner.", + "amount": 20000, + "currency": "INR" + }).then((response) => { + + itemId = response.id + assert.ok(response.hasOwnProperty('id')) + assert.ok(response.hasOwnProperty('name')) + done() + }).catch(err => console.log(err)) + }) + + it('fetch item', (done) => { + rzpInstance.items.fetch(itemId).then((response) => { + assert.ok(response.hasOwnProperty('id')) + assert.ok(response.hasOwnProperty('name')) + done() + }).catch(err => console.log(err)) + }) + + it('fetch all items', (done) => { + rzpInstance.items.all().then((response) => { + assert.ok(response.hasOwnProperty('entity')) + assert.ok(response.hasOwnProperty('items')) + done() + }).catch(err => console.log(err)) + }) + + it('edit item', (done) => { + let params = { + "name": "Book / Ignited Minds - Updated name!", + "description": "New descirption too. :).", + "amount": 20000, + "currency": "INR", + "active": true + } + + rzpInstance.items.edit(itemId, params).then((response) => { + assert.ok(response.hasOwnProperty('id')) + assert.ok((response.id === itemId)) + done() + }).catch(err => console.log(err)) + }) + + it('delete items', (done) => { + rzpInstance.items.delete(itemId).then((response) => { + assert.ok((typeof response === 'object')) + done() + }).catch(err => console.log(err)) + }) +}) diff --git a/test_prod/resources/plans.spec.js b/test_prod/resources/plans.spec.js new file mode 100644 index 00000000..8f33fd18 --- /dev/null +++ b/test_prod/resources/plans.spec.js @@ -0,0 +1,51 @@ +'use strict' + +var assert = require('assert'); +const rzpInstance = require('../razorpay') + +let planId = null; + +describe('PLANS', () => { + + it('plan create request', (done) => { + + rzpInstance.plans.create({ + "period": "weekly", + "interval": 1, + "item": { + "name": "Test plan - Weekly", + "amount": 69900, + "currency": "INR", + "description": "Description for the test plan" + }, + "notes": { + "notes_key_1": "Tea, Earl Grey, Hot", + "notes_key_2": "Tea, Earl Grey… decaf." + } + }).then((response) => { + + planId = response.id + assert.ok(response.hasOwnProperty('id')) + assert.ok(response.hasOwnProperty('entity')) + done() + }).catch(err => console.log(err)) + }) + + it('fetch plan', (done) => { + rzpInstance.plans.fetch(planId).then((response) => { + assert.ok(response.hasOwnProperty('id')) + assert.ok(response.hasOwnProperty('entity')) + done() + }).catch(err => console.log(err)) + }) + + it('fetch all plans', (done) => { + rzpInstance.items.all({ + count : 1 + }).then((response) => { + assert.ok(response.hasOwnProperty('entity')) + assert.ok(response.hasOwnProperty('items')) + done() + }).catch(err => console.log(err)) + }) +}) From a87d90af2cf6f0072f6485beebfeca951c2d21b5 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:23:34 +0530 Subject: [PATCH 3/6] Create prod_ci.yml --- .github/workflows/prod_ci.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/prod_ci.yml diff --git a/.github/workflows/prod_ci.yml b/.github/workflows/prod_ci.yml new file mode 100644 index 00000000..9ed3e5e1 --- /dev/null +++ b/.github/workflows/prod_ci.yml @@ -0,0 +1,32 @@ +name: e2e prod test +on: + push: + branches: + - master + tags: + - v[0-9]+.[0-9]+.[0-9]+* + pull_request: + branches: + - master +jobs: + test: + name: Run tests and publish test coverage + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm install + - name: Run tests + run: npm run test_prod + env: + API_KEY: ${{ secrets.API_KEY }} + API_SECRET: ${{ secrets.API_SECRET }} From 03bbdc8b1dd513ced6f373a54b75047e5b1b068d Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:27:47 +0530 Subject: [PATCH 4/6] Update razorpay.js --- test_prod/razorpay.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test_prod/razorpay.js b/test_prod/razorpay.js index 52739e22..5c2c49c4 100644 --- a/test_prod/razorpay.js +++ b/test_prod/razorpay.js @@ -1,8 +1,25 @@ 'use strict'; const Razorpay = require("../dist/razorpay"); +let request = require('request-promise'); -module.exports = new Razorpay({ +class RazorpayBeta extends Razorpay { + constructor(options) { + super(options) + this.api.rq = request.defaults({ + baseUrl: options.hostUrl, + json: true, + auth: { + user: options.key_id, + pass: options.key_secret + } + }) + } +} + + +module.exports = new RazorpayBeta({ key_id: process.env.API_KEY || "", - key_secret: process.env.API_SECRET || "" + key_secret: process.env.API_SECRET || "", + hostUrl : "https://api-web.dev.razorpay.in" }); From a43aba776885db5fae035e241b8bd02ac33ad707 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:28:15 +0530 Subject: [PATCH 5/6] revert changes --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 642f7f1e..03390d0a 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,7 @@ "build": "npm run clean && npm run build:commonjs && npm run cp-ts", "debug": "npm run build && node-debug examples/index.js", "test": "npm run build && mocha --recursive --require babel-register test/ && nyc --reporter=text mocha", - "coverage": "nyc report --reporter=text-lcov > coverage.lcov", - "test_prod": "npm run build && mocha --timeout 10000 --recursive --require babel-register test_prod/" + "coverage": "nyc report --reporter=text-lcov > coverage.lcov" }, "repository": { "type": "git", From 93eab27fb5eb4420dd1f3e4ebc9d5707e30f3e80 Mon Sep 17 00:00:00 2001 From: Ankit Das <89454448+ankitdas13@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:30:04 +0530 Subject: [PATCH 6/6] Update prod_ci.yml --- .github/workflows/prod_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/prod_ci.yml b/.github/workflows/prod_ci.yml index 9ed3e5e1..ec3f8e92 100644 --- a/.github/workflows/prod_ci.yml +++ b/.github/workflows/prod_ci.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: npm install - name: Run tests - run: npm run test_prod + run: npm run env -- mocha --timeout 10000 --recursive --require babel-register test_prod/ env: API_KEY: ${{ secrets.API_KEY }} API_SECRET: ${{ secrets.API_SECRET }}