From e949264dc737e0f840f6f0371a4ff29786f033f8 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Kunchapu Date: Thu, 9 Nov 2023 14:26:46 +0530 Subject: [PATCH 01/28] Basic Test Setup --- .gitignore | 1 + package.json | 17 ++++++++++++----- test/example.spec.ts | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 test/example.spec.ts diff --git a/.gitignore b/.gitignore index 149b576..dbd93e7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ wwwroot/*.js node_modules typings dist +package-lock.json diff --git a/package.json b/package.json index 353afe4..8fd00b3 100644 --- a/package.json +++ b/package.json @@ -21,14 +21,21 @@ "sideEffects": false, "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", - "prepare": "npm run build" + "prepare": "npm run build", + "test": "mocha dist/test/**/**.js" }, "dependencies": { - "axios": "1.5.1", - "@sentry/node": "^7.73.0" + "@sentry/node": "^7.73.0", + "axios": "1.5.1" }, "devDependencies": { + "@types/chai": "^4.3.10", + "@types/mocha": "^10.0.4", "@types/node": "^12.11.5", - "typescript": "^4.0" + "@types/sinon": "^17.0.1", + "chai": "^4.3.10", + "mocha": "^10.2.0", + "sinon": "^17.0.1", + "typescript": "^4.9.5" } -} +} \ No newline at end of file diff --git a/test/example.spec.ts b/test/example.spec.ts new file mode 100644 index 0000000..fcba883 --- /dev/null +++ b/test/example.spec.ts @@ -0,0 +1,35 @@ +import * as assert from "assert"; +import { Cashfree } from "./../api"; +import { expect } from 'chai'; + +Cashfree.XClientId = "TEST41754194f2067b4b76b61f6d7f145714"; +Cashfree.XClientSecret = "TEST3271ca1df72fb0bef2d947f1f91ec3467d90d22e"; +Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; + +it('Create Order', function (done) { + var blah = 'foo'; + var request = { + "order_amount": 3005, + "order_currency": "INR", + "customer_details": { + "customer_id": "iij", + "customer_name": "abcd", + "customer_email": "success@eligibility.com", + "customer_phone": "9999999999" + }, + + "order_note": "Test order", + "order_tags": { + "abc": "def" + } + } + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.order_currency, "INR") + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); \ No newline at end of file From 58b986538dccb04f2c324b9e16b5fb21a3a4c9fb Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 15:41:53 +0530 Subject: [PATCH 02/28] added env for secrets --- test/example.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/example.spec.ts b/test/example.spec.ts index fcba883..4e2ee70 100644 --- a/test/example.spec.ts +++ b/test/example.spec.ts @@ -2,8 +2,8 @@ import * as assert from "assert"; import { Cashfree } from "./../api"; import { expect } from 'chai'; -Cashfree.XClientId = "TEST41754194f2067b4b76b61f6d7f145714"; -Cashfree.XClientSecret = "TEST3271ca1df72fb0bef2d947f1f91ec3467d90d22e"; +Cashfree.XClientId = process.env.CLIENT_ID; +Cashfree.XClientSecret = process.env.SECRET_KEY; Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; it('Create Order', function (done) { @@ -24,6 +24,7 @@ it('Create Order', function (done) { } } Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + console.log(response.data.order_id) assert.equal(response.data.order_currency, "INR") done() }).catch((error) => { From d228fabbc2d99cf6c7cb2e1ffe96f202b6ec2e66 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 17:14:01 +0530 Subject: [PATCH 03/28] added test results --- .gitignore | 1 + package.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dbd93e7..3dc0dce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules typings dist package-lock.json +test-results \ No newline at end of file diff --git a/package.json b/package.json index 8fd00b3..774c959 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", "prepare": "npm run build", - "test": "mocha dist/test/**/**.js" + "test": "mocha dist/test/**/**.js --reporter mocha-junit-reporter --reporter-options mochaFile=./test-results/results.xml" }, "dependencies": { "@sentry/node": "^7.73.0", @@ -35,6 +35,7 @@ "@types/sinon": "^17.0.1", "chai": "^4.3.10", "mocha": "^10.2.0", + "mocha-junit-reporter": "^2.2.1", "sinon": "^17.0.1", "typescript": "^4.9.5" } From 87587f068ad15a81b585a844f1930e2a5556b419 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 17:55:08 +0530 Subject: [PATCH 04/28] added test results --- .github/workflows/run-tests.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/run-tests.yml diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..7f281a7 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,20 @@ +name: Trigger Tests on Pull Request. + +on: + pull_request: + branches: + - main + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20.x' + - name: Install dependencies + run: npm install From 70260f1eb51991d4d54b59c71086522ca568cb44 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 18:10:11 +0530 Subject: [PATCH 05/28] Added Run Tests step --- .github/workflows/run-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7f281a7..d5a0672 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,3 +18,9 @@ jobs: node-version: '20.x' - name: Install dependencies run: npm install + - name: Run Tests + run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test + env: + PG_CLIENT_ID: ${{ secrets.XCLIENTIDSANDBOX }} + PG_CLIENT_SECRET: ${{ secrets.XCLIENTSECRETSANDBOX }} + From 45b891b798a3e50a01e79e0137fc220fc81c005e Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 18:19:24 +0530 Subject: [PATCH 06/28] debug --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d5a0672..44fb24a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: - name: Install dependencies run: npm install - name: Run Tests - run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test + run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test && echo $PG_CLIENT_ID > a.txt && cat a.txt env: PG_CLIENT_ID: ${{ secrets.XCLIENTIDSANDBOX }} PG_CLIENT_SECRET: ${{ secrets.XCLIENTSECRETSANDBOX }} From 3d467c3bd5567ecac0f5dda3c38d538efd7b846b Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 18:23:32 +0530 Subject: [PATCH 07/28] debug --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 44fb24a..d5a0672 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,7 +19,7 @@ jobs: - name: Install dependencies run: npm install - name: Run Tests - run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test && echo $PG_CLIENT_ID > a.txt && cat a.txt + run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: PG_CLIENT_ID: ${{ secrets.XCLIENTIDSANDBOX }} PG_CLIENT_SECRET: ${{ secrets.XCLIENTSECRETSANDBOX }} From 62f4a058982e9a8a409874fafb5f2a4fbf37d132 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 9 Nov 2023 18:43:10 +0530 Subject: [PATCH 08/28] cc --- test/example.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/example.spec.ts b/test/example.spec.ts index 4e2ee70..6f2bc82 100644 --- a/test/example.spec.ts +++ b/test/example.spec.ts @@ -25,7 +25,7 @@ it('Create Order', function (done) { } Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { console.log(response.data.order_id) - assert.equal(response.data.order_currency, "INR") + assert.equal(response.data.order_currency, "INRs") done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) From b94ac9cb08cdd542e9ebc986d90f99f152dbfcaf Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Thu, 16 Nov 2023 16:05:18 +0530 Subject: [PATCH 09/28] fixed failed test --- test/example.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/example.spec.ts b/test/example.spec.ts index 6f2bc82..4e2ee70 100644 --- a/test/example.spec.ts +++ b/test/example.spec.ts @@ -25,7 +25,7 @@ it('Create Order', function (done) { } Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { console.log(response.data.order_id) - assert.equal(response.data.order_currency, "INRs") + assert.equal(response.data.order_currency, "INR") done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) From 8171868d4c7d9191990ea9272331a22d7a0c1e29 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Mon, 20 Nov 2023 13:58:03 +0530 Subject: [PATCH 10/28] added tests --- package.json | 2 +- test/example.spec.ts | 36 ----------- test/orders.spec.ts | 142 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 37 deletions(-) delete mode 100644 test/example.spec.ts create mode 100644 test/orders.spec.ts diff --git a/package.json b/package.json index 774c959..27ee1f1 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", "prepare": "npm run build", - "test": "mocha dist/test/**/**.js --reporter mocha-junit-reporter --reporter-options mochaFile=./test-results/results.xml" + "test": "mocha dist/test/**/**.js" }, "dependencies": { "@sentry/node": "^7.73.0", diff --git a/test/example.spec.ts b/test/example.spec.ts deleted file mode 100644 index 4e2ee70..0000000 --- a/test/example.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -import * as assert from "assert"; -import { Cashfree } from "./../api"; -import { expect } from 'chai'; - -Cashfree.XClientId = process.env.CLIENT_ID; -Cashfree.XClientSecret = process.env.SECRET_KEY; -Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; - -it('Create Order', function (done) { - var blah = 'foo'; - var request = { - "order_amount": 3005, - "order_currency": "INR", - "customer_details": { - "customer_id": "iij", - "customer_name": "abcd", - "customer_email": "success@eligibility.com", - "customer_phone": "9999999999" - }, - - "order_note": "Test order", - "order_tags": { - "abc": "def" - } - } - Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { - console.log(response.data.order_id) - assert.equal(response.data.order_currency, "INR") - done() - }).catch((error) => { - console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) - assert.fail("Fail error message") - done() - }); - -}); \ No newline at end of file diff --git a/test/orders.spec.ts b/test/orders.spec.ts new file mode 100644 index 0000000..0bc574e --- /dev/null +++ b/test/orders.spec.ts @@ -0,0 +1,142 @@ +import * as assert from "assert"; +import { Cashfree } from "../api"; +import { expect } from 'chai'; + +Cashfree.XClientId = process.env.CLIENT_ID; +Cashfree.XClientSecret = process.env.SECRET_KEY; +Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; + +var orderId = '' +var paymentSessionId = '' + + +function getCurrentTimeStamp() { + var today = new Date(); + var date = today.getFullYear() + (today.getMonth() + 1) + today.getDate(); + var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds; + var dateTime = date + ' ' + time; + return dateTime +} + + +function setOrderDetails(order_id: string, payment_session_id: string) { + orderId = order_id + paymentSessionId = payment_session_id +} + +it('Create Order', function (done) { + var blah = 'foo'; + var request = { + "order_amount": 3005, + "order_currency": "INR", + "customer_details": { + "customer_id": "iij", + "customer_name": "abcd", + "customer_email": "success@eligibility.com", + "customer_phone": "9999999999" + }, + + "order_note": "Test order", + "order_tags": { + "abc": "def" + } + } + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.order_currency, "INR") + setOrderDetails(response.data.order_id, response.data.payment_session_id) + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); + +it('Get Order', function (done) { + Cashfree.PGFetchOrder("2022-09-01", orderId).then((response) => { + assert.equal(response.data.order_currency, "INR") + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); + + +it('Get Payments For an Order', function (done) { + Cashfree.PGOrderFetchPayments("2022-09-01", orderId).then((response) => { + console.log(response.data) + // console.log(response.data.order_currency) + // assert.equal(response.data.order_currency, "INR") + // setOrderDetails(response.data.order_id) + // console.log(orderId) + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); + +it('Get Payment by PaymentId for an Order', function (done) { + Cashfree.PGOrderFetchPayment("2022-09-01", orderId, "9s99sjs").then((response) => { + console.log(response.data) + // console.log(response.data.order_currency) + // assert.equal(response.data.order_currency, "INR") + // setOrderDetails(response.data.order_id) + // console.log(orderId) + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); + +it('Create Payment Link', function (done) { + var request = { + "link_amount": 1, + "link_id": "Automated_Test_f", + "link_currency": "INR", + "customer_details": { + "customer_name": "John Doe", + "customer_phone": "9292229292", + "customer_email": "john@cashfree.com" + + }, + "link_purpose": "qui", + "link_partial_payments": false, + "link_minimum_partial_amount": 77634560.22892892, + "link_notify": { + "send_sms": false, + "send_email": true + }, + "link_auto_reminders": false, + "link_notes": { + "key_1": "value_1", + "key_2": "value_2" + }, + "link_meta": { + "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", + "upi_intent": false + } + } + Cashfree.PGCreateLink("2022-09-01", request).then((response) => { + // console.log(response.data.order_currency) + // assert.equal(response.data.order_currency, "INR") + // setOrderDetails(response.data.order_id) + // console.log(orderId) + console.log(response.data) + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); \ No newline at end of file From 5e4df2204745cc2567888e183ab8fe15b366e084 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Mon, 20 Nov 2023 14:11:25 +0530 Subject: [PATCH 11/28] added test coverage link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d15bed..57eac3b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Cashfree PG Node SDK ![GitHub](https://img.shields.io/github/license/cashfree/cashfree-pg-sdk-nodejs) ![Discord](https://img.shields.io/discord/931125665669972018?label=discord) ![GitHub last commit (branch)](https://img.shields.io/github/last-commit/cashfree/cashfree-pg-sdk-nodejs/main) ![GitHub release (with filter)](https://img.shields.io/github/v/release/cashfree/cashfree-pg-sdk-nodejs?label=latest) ![npm](https://img.shields.io/npm/v/cashfree-pg) ![GitHub forks](https://img.shields.io/github/forks/cashfree/cashfree-pg-sdk-nodejs) +[![Coverage Status](https://coveralls.io/repos/github/cashfree/cashfree-pg-sdk-nodejs/badge.svg?branch=automate-node-js-tests)](https://coveralls.io/github/cashfree/cashfree-pg-sdk-nodejs?branch=automate-node-js-tests) The Cashfree PG Node SDK offers a convenient solution to access [Cashfree PG APIs](https://docs.cashfree.com/reference/pg-new-apis-endpoint) from a server-side JavaScript applications. From d79a03298ad7e6e56d584ced103d5ac840782767 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Mon, 20 Nov 2023 14:29:06 +0530 Subject: [PATCH 12/28] fixed failed tests --- test/orders.spec.ts | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/test/orders.spec.ts b/test/orders.spec.ts index 0bc574e..6c54ead 100644 --- a/test/orders.spec.ts +++ b/test/orders.spec.ts @@ -13,8 +13,8 @@ var paymentSessionId = '' function getCurrentTimeStamp() { var today = new Date(); var date = today.getFullYear() + (today.getMonth() + 1) + today.getDate(); - var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds; - var dateTime = date + ' ' + time; + var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds(); + var dateTime = date + '' + time; return dateTime } @@ -82,26 +82,11 @@ it('Get Payments For an Order', function (done) { }); -it('Get Payment by PaymentId for an Order', function (done) { - Cashfree.PGOrderFetchPayment("2022-09-01", orderId, "9s99sjs").then((response) => { - console.log(response.data) - // console.log(response.data.order_currency) - // assert.equal(response.data.order_currency, "INR") - // setOrderDetails(response.data.order_id) - // console.log(orderId) - done() - }).catch((error) => { - console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) - assert.fail("Fail error message") - done() - }); - -}); - it('Create Payment Link', function (done) { + var link_id = "Automated_Test_" + getCurrentTimeStamp() var request = { "link_amount": 1, - "link_id": "Automated_Test_f", + "link_id": link_id, "link_currency": "INR", "customer_details": { "customer_name": "John Doe", @@ -131,7 +116,6 @@ it('Create Payment Link', function (done) { // assert.equal(response.data.order_currency, "INR") // setOrderDetails(response.data.order_id) // console.log(orderId) - console.log(response.data) done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) From eb1fe1cbc2e3212533f1e5b4c397bb6faddfd7e7 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Mon, 20 Nov 2023 16:02:20 +0530 Subject: [PATCH 13/28] change --- test/orders.spec.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/orders.spec.ts b/test/orders.spec.ts index 6c54ead..83f0f2a 100644 --- a/test/orders.spec.ts +++ b/test/orders.spec.ts @@ -24,7 +24,7 @@ function setOrderDetails(order_id: string, payment_session_id: string) { paymentSessionId = payment_session_id } -it('Create Order', function (done) { +it('Create Order Test', function (done) { var blah = 'foo'; var request = { "order_amount": 3005, @@ -42,6 +42,7 @@ it('Create Order', function (done) { } } Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.order_amount, request.order_amount) assert.equal(response.data.order_currency, "INR") setOrderDetails(response.data.order_id, response.data.payment_session_id) done() @@ -53,7 +54,7 @@ it('Create Order', function (done) { }); -it('Get Order', function (done) { +it('Get Order Test', function (done) { Cashfree.PGFetchOrder("2022-09-01", orderId).then((response) => { assert.equal(response.data.order_currency, "INR") done() @@ -66,9 +67,8 @@ it('Get Order', function (done) { }); -it('Get Payments For an Order', function (done) { +it('Get Payments For an Order Test', function (done) { Cashfree.PGOrderFetchPayments("2022-09-01", orderId).then((response) => { - console.log(response.data) // console.log(response.data.order_currency) // assert.equal(response.data.order_currency, "INR") // setOrderDetails(response.data.order_id) @@ -82,7 +82,7 @@ it('Get Payments For an Order', function (done) { }); -it('Create Payment Link', function (done) { +it('Create Payment Link Test', function (done) { var link_id = "Automated_Test_" + getCurrentTimeStamp() var request = { "link_amount": 1, @@ -112,10 +112,6 @@ it('Create Payment Link', function (done) { } } Cashfree.PGCreateLink("2022-09-01", request).then((response) => { - // console.log(response.data.order_currency) - // assert.equal(response.data.order_currency, "INR") - // setOrderDetails(response.data.order_id) - // console.log(orderId) done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) From f91108a662eeebece8ab462c293bafb77ffd92b8 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Wed, 22 Nov 2023 16:28:53 +0530 Subject: [PATCH 14/28] Removed Mocha and Added Jest --- jest.config.js | 4 + package.json | 7 +- test/orders.spec.ts => tests/orders.test.ts | 90 +++++++++++++++++++-- tsconfig.json | 3 +- 4 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 jest.config.js rename test/orders.spec.ts => tests/orders.test.ts (59%) diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..f7475c3 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: "ts-jest", + testEnvironment: "node", +}; \ No newline at end of file diff --git a/package.json b/package.json index 27ee1f1..0f40fbd 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", "prepare": "npm run build", - "test": "mocha dist/test/**/**.js" + "test": "jest" }, "dependencies": { "@sentry/node": "^7.73.0", @@ -30,13 +30,14 @@ }, "devDependencies": { "@types/chai": "^4.3.10", - "@types/mocha": "^10.0.4", + "@types/jest": "^29.5.10", "@types/node": "^12.11.5", "@types/sinon": "^17.0.1", "chai": "^4.3.10", - "mocha": "^10.2.0", + "jest": "^29.7.0", "mocha-junit-reporter": "^2.2.1", "sinon": "^17.0.1", + "ts-jest": "^29.1.1", "typescript": "^4.9.5" } } \ No newline at end of file diff --git a/test/orders.spec.ts b/tests/orders.test.ts similarity index 59% rename from test/orders.spec.ts rename to tests/orders.test.ts index 83f0f2a..3990128 100644 --- a/test/orders.spec.ts +++ b/tests/orders.test.ts @@ -1,5 +1,7 @@ import * as assert from "assert"; -import { Cashfree } from "../api"; +import { Cashfree, CreateOrderRequest, UpiChannelEnum, OrderCreateRefundRequestRefundSpeedEnum } from "../api"; +const { execSync } = require('child_process'); + import { expect } from 'chai'; Cashfree.XClientId = process.env.CLIENT_ID; @@ -8,6 +10,7 @@ Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; var orderId = '' var paymentSessionId = '' +var successfulTxnId = '' function getCurrentTimeStamp() { @@ -24,6 +27,58 @@ function setOrderDetails(order_id: string, payment_session_id: string) { paymentSessionId = payment_session_id } +function setSuccessfulTxnId(txnId: string) { + successfulTxnId = txnId +} + +async function createOrder() { + var blah = 'foo'; + var request = { + "order_amount": 3005, + "order_currency": "INR", + "customer_details": { + "customer_id": "iij", + "customer_name": "abcd", + "customer_email": "success@eligibility.com", + "customer_phone": "9999999999" + }, + + "order_note": "Test order", + "order_tags": { + "abc": "def" + } + } + + await Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + setOrderDetails(response.data.order_id, response.data.payment_session_id) + + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + }); +} + +async function createTxnWithStatus(payment_session_id: string, status: string) { + var upi_id = "testsuccess@gocash" + if (status === "failure") { + upi_id = "testfail@gocash" + } + var link_id = "Automated_Test_" + getCurrentTimeStamp() + // console.log("Payment SessionId: " + payment_session_id) + var request = { + "payment_session_id": payment_session_id, + "payment_method": { + "upi": { + "upi_id": upi_id, + "channel": UpiChannelEnum.COLLECT + } + } + } + await Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + }).catch((error) => { + //console.log(error) + }); +} + it('Create Order Test', function (done) { var blah = 'foo'; var request = { @@ -41,6 +96,7 @@ it('Create Order Test', function (done) { "abc": "def" } } + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { assert.equal(response.data.order_amount, request.order_amount) assert.equal(response.data.order_currency, "INR") @@ -54,6 +110,13 @@ it('Create Order Test', function (done) { }); +it('Order Pay Collect Test', function () { + createOrder(); + execSync('sleep 1'); + // console.log("Payment: " + paymentSessionId) + createTxnWithStatus(paymentSessionId, '') +}); + it('Get Order Test', function (done) { Cashfree.PGFetchOrder("2022-09-01", orderId).then((response) => { assert.equal(response.data.order_currency, "INR") @@ -66,13 +129,10 @@ it('Get Order Test', function (done) { }); - it('Get Payments For an Order Test', function (done) { + createOrder() + createTxnWithStatus(paymentSessionId, '') Cashfree.PGOrderFetchPayments("2022-09-01", orderId).then((response) => { - // console.log(response.data.order_currency) - // assert.equal(response.data.order_currency, "INR") - // setOrderDetails(response.data.order_id) - // console.log(orderId) done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) @@ -114,9 +174,27 @@ it('Create Payment Link Test', function (done) { Cashfree.PGCreateLink("2022-09-01", request).then((response) => { done() }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) assert.fail("Fail error message") done() }); +}); + + +it('Create Refund Test', function (done) { + var request = { + "refund_amount": 1, + "refund_id": "Refund_id_" + getCurrentTimeStamp(), + "refund_note": "initiated refund by automation" + } + + Cashfree.PGOrderCreateRefund("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", request).then((response) => { + done() + }).catch((error) => { + console.log(error) + assert.fail("Fail error message") + done() + }); }); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index bfac57c..fd38bce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "ignoreDeprecations": "5.0", "exclude": [ "dist", + "tests", "node_modules" ] -} +} \ No newline at end of file From 311a38d743fb4ad5b110e2e13a885a7cd5897c6e Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Wed, 22 Nov 2023 16:33:34 +0530 Subject: [PATCH 15/28] Splitted tests to different files --- tests/links.test.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++ tests/orders.test.ts | 41 ---------------------------- 2 files changed, 64 insertions(+), 41 deletions(-) create mode 100644 tests/links.test.ts diff --git a/tests/links.test.ts b/tests/links.test.ts new file mode 100644 index 0000000..39e30d0 --- /dev/null +++ b/tests/links.test.ts @@ -0,0 +1,64 @@ +import * as assert from "assert"; +import { Cashfree, CreateOrderRequest, UpiChannelEnum, OrderCreateRefundRequestRefundSpeedEnum } from "../api"; +const { execSync } = require('child_process'); + +import { expect } from 'chai'; + +Cashfree.XClientId = process.env.CLIENT_ID; +Cashfree.XClientSecret = process.env.SECRET_KEY; +Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; + +var orderId = '' +var paymentSessionId = '' +var successfulTxnId = '' + + +function getCurrentTimeStamp() { + var today = new Date(); + var date = today.getFullYear() + (today.getMonth() + 1) + today.getDate(); + var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds(); + var dateTime = date + '' + time; + return dateTime +} + + +it('Create Payment Link Test', function (done) { + var link_id = "Automated_Test_" + getCurrentTimeStamp() + var request = { + "link_amount": 1, + "link_id": link_id, + "link_currency": "INR", + "customer_details": { + "customer_name": "John Doe", + "customer_phone": "9292229292", + "customer_email": "john@cashfree.com" + + }, + "link_purpose": "qui", + "link_partial_payments": false, + "link_minimum_partial_amount": 77634560.22892892, + "link_notify": { + "send_sms": false, + "send_email": true + }, + "link_auto_reminders": false, + "link_notes": { + "key_1": "value_1", + "key_2": "value_2" + }, + "link_meta": { + "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", + "upi_intent": false + } + } + Cashfree.PGCreateLink("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); + +}); + diff --git a/tests/orders.test.ts b/tests/orders.test.ts index 3990128..2e942fc 100644 --- a/tests/orders.test.ts +++ b/tests/orders.test.ts @@ -142,47 +142,6 @@ it('Get Payments For an Order Test', function (done) { }); -it('Create Payment Link Test', function (done) { - var link_id = "Automated_Test_" + getCurrentTimeStamp() - var request = { - "link_amount": 1, - "link_id": link_id, - "link_currency": "INR", - "customer_details": { - "customer_name": "John Doe", - "customer_phone": "9292229292", - "customer_email": "john@cashfree.com" - - }, - "link_purpose": "qui", - "link_partial_payments": false, - "link_minimum_partial_amount": 77634560.22892892, - "link_notify": { - "send_sms": false, - "send_email": true - }, - "link_auto_reminders": false, - "link_notes": { - "key_1": "value_1", - "key_2": "value_2" - }, - "link_meta": { - "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", - "upi_intent": false - } - } - Cashfree.PGCreateLink("2022-09-01", request).then((response) => { - done() - }).catch((error) => { - - console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) - assert.fail("Fail error message") - done() - }); - -}); - - it('Create Refund Test', function (done) { var request = { "refund_amount": 1, From 7966a6d3b16ee47aa69037f6305675a913570c4d Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:28:43 +0530 Subject: [PATCH 16/28] added tests --- .gitignore | 1 + package.json | 2 +- tests/links.test.ts | 64 ------ tests/orders.test.ts | 512 ++++++++++++++++++++++++++++++++++++++----- 4 files changed, 464 insertions(+), 115 deletions(-) delete mode 100644 tests/links.test.ts diff --git a/.gitignore b/.gitignore index 3dc0dce..ad10e17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ wwwroot/*.js node_modules +coverage typings dist package-lock.json diff --git a/package.json b/package.json index 0f40fbd..91660ee 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", "prepare": "npm run build", - "test": "jest" + "test": "jest --coverage" }, "dependencies": { "@sentry/node": "^7.73.0", diff --git a/tests/links.test.ts b/tests/links.test.ts deleted file mode 100644 index 39e30d0..0000000 --- a/tests/links.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -import * as assert from "assert"; -import { Cashfree, CreateOrderRequest, UpiChannelEnum, OrderCreateRefundRequestRefundSpeedEnum } from "../api"; -const { execSync } = require('child_process'); - -import { expect } from 'chai'; - -Cashfree.XClientId = process.env.CLIENT_ID; -Cashfree.XClientSecret = process.env.SECRET_KEY; -Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; - -var orderId = '' -var paymentSessionId = '' -var successfulTxnId = '' - - -function getCurrentTimeStamp() { - var today = new Date(); - var date = today.getFullYear() + (today.getMonth() + 1) + today.getDate(); - var time = "" + today.getHours() + today.getMinutes() + today.getSeconds() + today.getMilliseconds(); - var dateTime = date + '' + time; - return dateTime -} - - -it('Create Payment Link Test', function (done) { - var link_id = "Automated_Test_" + getCurrentTimeStamp() - var request = { - "link_amount": 1, - "link_id": link_id, - "link_currency": "INR", - "customer_details": { - "customer_name": "John Doe", - "customer_phone": "9292229292", - "customer_email": "john@cashfree.com" - - }, - "link_purpose": "qui", - "link_partial_payments": false, - "link_minimum_partial_amount": 77634560.22892892, - "link_notify": { - "send_sms": false, - "send_email": true - }, - "link_auto_reminders": false, - "link_notes": { - "key_1": "value_1", - "key_2": "value_2" - }, - "link_meta": { - "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", - "upi_intent": false - } - } - Cashfree.PGCreateLink("2022-09-01", request).then((response) => { - done() - }).catch((error) => { - - console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) - assert.fail("Fail error message") - done() - }); - -}); - diff --git a/tests/orders.test.ts b/tests/orders.test.ts index 2e942fc..3258177 100644 --- a/tests/orders.test.ts +++ b/tests/orders.test.ts @@ -1,17 +1,15 @@ import * as assert from "assert"; -import { Cashfree, CreateOrderRequest, UpiChannelEnum, OrderCreateRefundRequestRefundSpeedEnum } from "../api"; +import { expect, jest, test } from '@jest/globals'; +import { Cashfree, UpiChannelEnum, AppProviderEnum, CardChannelEnum, OfferTncOfferTncTypeEnum, OfferType, DiscountDetailsDiscountTypeEnum } from "../api"; const { execSync } = require('child_process'); -import { expect } from 'chai'; - Cashfree.XClientId = process.env.CLIENT_ID; Cashfree.XClientSecret = process.env.SECRET_KEY; Cashfree.XEnvironment = Cashfree.Environment.SANDBOX; var orderId = '' var paymentSessionId = '' -var successfulTxnId = '' - +var orderAmount = 3000; function getCurrentTimeStamp() { var today = new Date(); @@ -21,20 +19,15 @@ function getCurrentTimeStamp() { return dateTime } - function setOrderDetails(order_id: string, payment_session_id: string) { orderId = order_id paymentSessionId = payment_session_id } -function setSuccessfulTxnId(txnId: string) { - successfulTxnId = txnId -} - -async function createOrder() { +it('Create Order Test', function (done) { var blah = 'foo'; var request = { - "order_amount": 3005, + "order_amount": orderAmount, "order_currency": "INR", "customer_details": { "customer_id": "iij", @@ -49,40 +42,57 @@ async function createOrder() { } } - await Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.order_amount, request.order_amount, "Amount is not matching") + assert.equal(response.data.order_currency, "INR", "Currency is not matching") + assert.equal(response.data.customer_details?.customer_id, response.data.customer_details?.customer_id, "Customer id is not matching") + assert.equal(response.data.customer_details?.customer_name, response.data.customer_details?.customer_name, "Customer name is not matching") + assert.equal(response.data.customer_details?.customer_email, response.data.customer_details?.customer_email, "Customer email is not matching") + assert.equal(response.data.customer_details?.customer_phone, response.data.customer_details?.customer_phone, "Customer phone is not matching") setOrderDetails(response.data.order_id, response.data.payment_session_id) - + done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() }); -} -async function createTxnWithStatus(payment_session_id: string, status: string) { - var upi_id = "testsuccess@gocash" - if (status === "failure") { - upi_id = "testfail@gocash" - } - var link_id = "Automated_Test_" + getCurrentTimeStamp() - // console.log("Payment SessionId: " + payment_session_id) +}); + + +it('Create Order with Invalid Currency Test', function (done) { + var currency = 'INaR'; var request = { - "payment_session_id": payment_session_id, - "payment_method": { - "upi": { - "upi_id": upi_id, - "channel": UpiChannelEnum.COLLECT - } + "order_amount": orderAmount, + "order_currency": currency, + "customer_details": { + "customer_id": "iij", + "customer_name": "abcd", + "customer_email": "success@eligibility.com", + "customer_phone": "9999999999" + }, + + "order_note": "Test order", + "order_tags": { + "abc": "def" } } - await Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { + assert.fail("Fail error message") + done() }).catch((error) => { - //console.log(error) + assert.equal(error.response.data.message, "order_currency : is not valid or not enabled. Value received: " + currency, "Link id is not matching") + assert.equal(error.response.data.code, "order_currency_invalid", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() }); -} -it('Create Order Test', function (done) { - var blah = 'foo'; +}); + +it('Create Order with Invalid Amount Test', function (done) { var request = { - "order_amount": 3005, + "order_amount": -3005, "order_currency": "INR", "customer_details": { "customer_id": "iij", @@ -98,27 +108,138 @@ it('Create Order Test', function (done) { } Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { - assert.equal(response.data.order_amount, request.order_amount) - assert.equal(response.data.order_currency, "INR") - setOrderDetails(response.data.order_id, response.data.payment_session_id) + assert.fail("Fail error message") done() }).catch((error) => { - console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.equal(error.response.data.message, "order_amount : Invalid amount entered ", "Link id is not matching") + assert.equal(error.response.data.code, "order_amount_invalid", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); + +}); + +it('Create Order with Empty Customer Phone Test', function (done) { + var request = { + "order_amount": orderAmount, + "order_currency": "INR", + "customer_details": { + "customer_id": "iij", + "customer_name": "abcd", + "customer_email": "success@eligibility.com", + "customer_phone": "" + }, + + "order_note": "Test order", + "order_tags": { + "abc": "def" + } + } + + Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { assert.fail("Fail error message") done() + }).catch((error) => { + assert.equal(error.response.data.message, "customer_details.customer_phone : is missing in the request. Value received: ", "Customer phone is not matching") + assert.equal(error.response.data.code, "customer_details.customer_phone_missing", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() }); }); -it('Order Pay Collect Test', function () { - createOrder(); - execSync('sleep 1'); - // console.log("Payment: " + paymentSessionId) - createTxnWithStatus(paymentSessionId, '') +it('Order Pay Net Banking Test', function (done) { + var request = { + "payment_session_id": paymentSessionId, + "payment_method": { + "netbanking": { + "netbanking_bank_code": 3087, + "channel": "link" + } + } + } + Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.channel, "link", "channel is not matching") + assert.equal(response.data.payment_method, "netbanking", "payment_method is not matching") + assert.strictEqual(Number(response.data.payment_amount) >= orderAmount, true, "Payment amount is less than order amount") + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + +it('Order Pay Card payment Test', function (done) { + var request = { + "payment_session_id": paymentSessionId, + "payment_method": { + "card": { + "channel": CardChannelEnum.LINK, + "card_number": "4838305610460100", + "card_holder_name": "Tushar Gupta", + "card_expiry_mm": "06", + "card_expiry_yy": "25", + "card_cvv": "123" + } + } + } + Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + assert.equal(response.data.channel, "link", "channel is not matching") + assert.equal(response.data.payment_method, "card", "payment_method is not matching") + assert.strictEqual(Number(response.data.payment_amount) >= orderAmount, true, "Payment amount is less than order amount") + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + +it('Order Pay Card payment with empty cvv Test', function (done) { + var request = { + "payment_session_id": paymentSessionId, + "payment_method": { + "card": { + "channel": CardChannelEnum.LINK, + "card_number": "4838305610460100", + "card_holder_name": "Tushar Gupta", + "card_expiry_mm": "06", + "card_expiry_yy": "25", + "card_cvv": "" + } + } + } + Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "card_cvv : is missing in the request. Value received: ", "Message is not matching") + assert.equal(error.response.data.code, "card_cvv_missing", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Order Pay Wallet Test', function (done) { + var request = { + "payment_session_id": paymentSessionId, + "payment_method": { + "app": { + "provider": AppProviderEnum.PHONEPE, + "phone": "8474090512", + "channel": "link" + } + } + } + Cashfree.PGPayOrder("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); }); it('Get Order Test', function (done) { - Cashfree.PGFetchOrder("2022-09-01", orderId).then((response) => { + Cashfree.PGFetchOrder("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => { assert.equal(response.data.order_currency, "INR") done() }).catch((error) => { @@ -126,13 +247,10 @@ it('Get Order Test', function (done) { assert.fail("Fail error message") done() }); - }); it('Get Payments For an Order Test', function (done) { - createOrder() - createTxnWithStatus(paymentSessionId, '') - Cashfree.PGOrderFetchPayments("2022-09-01", orderId).then((response) => { + Cashfree.PGOrderFetchPayments("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => { done() }).catch((error) => { console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) @@ -148,12 +266,306 @@ it('Create Refund Test', function (done) { "refund_id": "Refund_id_" + getCurrentTimeStamp(), "refund_note": "initiated refund by automation" } + Cashfree.PGOrderCreateRefund("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", request).then((response) => { + done() + }).catch((error) => { + console.log(error.response.data) + assert.fail("Fail error message") + done() + }); +}); + +it('Create Refund with negative refund amount Test', function (done) { + var request = { + "refund_amount": -1, + "refund_id": "Refund_id_" + getCurrentTimeStamp(), + "refund_note": "initiated refund by automation" + } Cashfree.PGOrderCreateRefund("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", request).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "refund_amount : Invalid amount entered ", "Link id is not matching") + assert.equal(error.response.data.code, "refund_amount_invalid", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Create Refund with invalid order id Test', function (done) { + var request = { + "refund_amount": 1, + "refund_id": "Refund_id_" + getCurrentTimeStamp(), + "refund_note": "initiated refund by automation" + } + var order_id = "Order_" + getCurrentTimeStamp() + Cashfree.PGOrderCreateRefund("2022-09-01", order_id, request).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "Order Reference Id does not exist", "Link id is not matching") + assert.equal(error.response.data.code, "order_not_found", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Fetch All Refunds Test', function (done) { + var order_id = "Order_" + getCurrentTimeStamp() + Cashfree.PGOrderFetchRefunds("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI").then((response) => { done() }).catch((error) => { - console.log(error) + console.log(error.response.data) assert.fail("Fail error message") done() }); -}); \ No newline at end of file +}); + +it('Fetch Refund Test', function (done) { + var order_id = "Order_" + getCurrentTimeStamp() + Cashfree.PGOrderFetchRefund("2022-09-01", "order_4175412YWdHafgWZLFYcyTKkzIqu9QJvI", "Refund_id_2060112241827").then((response) => { + done() + }).catch((error) => { + console.log(error.response.data) + assert.fail("Fail error message") + done() + }); +}); + + + +it('Create Payment Link Test', function (done) { + var link_id = "Automated_Test_" + getCurrentTimeStamp() + var request = { + "link_amount": 1, + "link_id": link_id, + "link_currency": "INR", + "customer_details": { + "customer_name": "John Doe", + "customer_phone": "9292229292", + "customer_email": "john@cashfree.com" + + }, + "link_purpose": "qui", + "link_partial_payments": false, + "link_minimum_partial_amount": 77634560.22892892, + "link_notify": { + "send_sms": false, + "send_email": true + }, + "link_auto_reminders": false, + "link_notes": { + "key_1": "value_1", + "key_2": "value_2" + }, + "link_meta": { + "notify_url": "https://ee08e626ecd88c61c85f5c69c0418cb5.m.pipedream.net", + "upi_intent": false + } + } + Cashfree.PGCreateLink("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); +}); + + +it('Fetch Payment Link Test', function (done) { + var link_id = "Automated_Test_188181" + Cashfree.PGFetchLink("2022-09-01", link_id).then((response) => { + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); +}); + +it('Cancel Payment Link Test', function (done) { + var link_id = "Automated_Test_188181" + Cashfree.PGCancelLink("2022-09-01", link_id).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "Only link in ACTIVE state can be cancelled", "Link id is not matching") + assert.equal(error.response.data.code, "link_not_active", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Fetch Payment Link with Invalid link id Test', function (done) { + var link_id = "jahha" + getCurrentTimeStamp() + Cashfree.PGFetchLink("2022-09-01", link_id).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "No request found with link Id " + link_id, "Link id is not matching") + assert.equal(error.response.data.code, "link_not_found", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Fetch Link Orders Test', function (done) { + var link_id = "Automated_Test_188181" + Cashfree.PGLinkFetchOrders("2022-09-01", link_id).then((response) => { + done() + }).catch((error) => { + console.log("Actual: " + error.actual + " Expected: " + error.expected + " Operator: " + error.operator) + assert.fail("Fail error message") + done() + }); +}); + +it('Fetch Link Orders with invalid link id Test', function (done) { + var link_id = "jajqq" + Cashfree.PGLinkFetchOrders("2022-09-01", link_id).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "No request found with link ID " + link_id, "Link id is not matching") + assert.equal(error.response.data.code, "link_not_found", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + + +it('Create Offer Test', function (done) { + var request = { + "offer_meta": { + "offer_title": "bat mann", + "offer_description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit", + "offer_code": "VISA1122", + "offer_start_time": "2024-01-01T08:09:51Z", + "offer_end_time": "2024-09-14T06:18:50Z" + }, + "offer_tnc": { + "offer_tnc_type": OfferTncOfferTncTypeEnum.TEXT, + "offer_tnc_value": "Lorem ipsum dolor sit amet" + }, + "offer_details": { + "offer_type": OfferType.DISCOUNT, + "discount_details": { + "discount_type": DiscountDetailsDiscountTypeEnum.PERCENTAGE, + "discount_value": "20.00", + "max_discount_amount": "150.00" + } + }, + "offer_validations": { + "min_amount": 223.0, + "max_allowed": 122, + "payment_method": { + "all": { + + } + } + } + } + Cashfree.PGCreateOffer("2022-09-01", request).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + console.log(error.response) + done() + }); +}); + +it('Get Offer Test', function (done) { + Cashfree.PGFetchOffer("2022-09-01", "a189050b-8f7e-4f1c-be5f-ba4bf58bdd6b").then((response) => { + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + +it('Fetch Eligibility Payment Methods Test', function (done) { + var request = { + "queries": { + "amount": 100 + } + } + Cashfree.PGEligibilityFetchPaymentMethods("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + +it('Fetch Eligibility Payment Methods With invalid amount Test', function (done) { + var request = { + "queries": { + "amount": -100 + } + } + Cashfree.PGEligibilityFetchPaymentMethods("2022-09-01", request).then((response) => { + assert.fail("Fail error message") + done() + }).catch((error) => { + assert.equal(error.response.data.message, "queries.amount : should be greater than 0", "Link id is not matching") + assert.equal(error.response.data.code, "queries.amount_invalid", "Code is not matching") + assert.equal(error.response.data.type, "invalid_request_error", "Type is not matching") + done() + }); +}); + +it('Settlement Reconcilation Test', function (done) { + var request = { + "pagination": { + "limit": 10 + }, + "filters": { + "start_date": "2023-03-01T00:00:00Z", + "end_date": "2023-03-21T23:59:59Z" + } + } + Cashfree.PGSettlementFetchRecon("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + + +it('PG Reconcilation Test', function (done) { + var request = { + "pagination": { + "limit": 10 + }, + "filters": { + "start_date": "2023-01-01T00:00:00Z", + "end_date": "2023-01-21T23:59:59Z" + } + } + Cashfree.PGFetchRecon("2022-09-01", request).then((response) => { + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + +it('Get Instrument By Id Test', function (done) { + var instrumemtId = "9f9477b7-61ea-4baa-b878-a7e63d978034" + var customerId = "iij" + Cashfree.PGCustomerFetchInstrument("2022-09-01", customerId, instrumemtId).then((response) => { + assert.equal(response.data.instrument_id, instrumemtId, "instrument_id is not matching") + assert.equal(response.data.customer_id, customerId, "instrument_id is not matching") + done() + }).catch((error) => { + assert.fail("Fail error message") + done() + }); +}); + + + + From 96af7aded8abf1805197e46df36e96f8d8116e1f Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:30:22 +0530 Subject: [PATCH 17/28] added tests --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 57eac3b..5326e61 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Cashfree PG Node SDK -![GitHub](https://img.shields.io/github/license/cashfree/cashfree-pg-sdk-nodejs) ![Discord](https://img.shields.io/discord/931125665669972018?label=discord) ![GitHub last commit (branch)](https://img.shields.io/github/last-commit/cashfree/cashfree-pg-sdk-nodejs/main) ![GitHub release (with filter)](https://img.shields.io/github/v/release/cashfree/cashfree-pg-sdk-nodejs?label=latest) ![npm](https://img.shields.io/npm/v/cashfree-pg) ![GitHub forks](https://img.shields.io/github/forks/cashfree/cashfree-pg-sdk-nodejs) -[![Coverage Status](https://coveralls.io/repos/github/cashfree/cashfree-pg-sdk-nodejs/badge.svg?branch=automate-node-js-tests)](https://coveralls.io/github/cashfree/cashfree-pg-sdk-nodejs?branch=automate-node-js-tests) +![GitHub](https://img.shields.io/github/license/cashfree/cashfree-pg-sdk-nodejs) ![Discord](https://img.shields.io/discord/931125665669972018?label=discord) ![GitHub last commit (branch)](https://img.shields.io/github/last-commit/cashfree/cashfree-pg-sdk-nodejs/main) ![GitHub release (with filter)](https://img.shields.io/github/v/release/cashfree/cashfree-pg-sdk-nodejs?label=latest) ![npm](https://img.shields.io/npm/v/cashfree-pg) ![GitHub forks](https://img.shields.io/github/forks/cashfree/cashfree-pg-sdk-nodejs) [![Tests](https://github.com/cashfree/cashfree-pg-sdk-nodejs/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/cashfree/cashfree-pg-sdk-nodejs/actions/workflows/run-tests.yml) [![Build and Publish](https://github.com/cashfree/cashfree-pg-sdk-nodejs/actions/workflows/publish.yml/badge.svg)](https://github.com/cashfree/cashfree-pg-sdk-nodejs/actions/workflows/publish.yml) The Cashfree PG Node SDK offers a convenient solution to access [Cashfree PG APIs](https://docs.cashfree.com/reference/pg-new-apis-endpoint) from a server-side JavaScript applications. From 883a2c4ed3429264dbd9c6d9231b9edfc93b392d Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:33:35 +0530 Subject: [PATCH 18/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d5a0672..abba897 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,7 +17,7 @@ jobs: with: node-version: '20.x' - name: Install dependencies - run: npm install + run: npm run build - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: From 65c4280ec8e0bd652209b63a3ac6a79c431b71f5 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:35:57 +0530 Subject: [PATCH 19/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index abba897..e7b5012 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,6 +17,7 @@ jobs: with: node-version: '20.x' - name: Install dependencies + run: node -v run: npm run build - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test From 483e0398062917df908c877fd5d217df8bf98423 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:37:15 +0530 Subject: [PATCH 20/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e7b5012..423500d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,7 +18,6 @@ jobs: node-version: '20.x' - name: Install dependencies run: node -v - run: npm run build - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: From 9824adf312da0989154bb45da0ad427aa073eac4 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:37:57 +0530 Subject: [PATCH 21/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 423500d..abba897 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,7 +17,7 @@ jobs: with: node-version: '20.x' - name: Install dependencies - run: node -v + run: npm run build - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: From 944515aec83f7828cb6356c21799734e8ac032ad Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:39:44 +0530 Subject: [PATCH 22/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index abba897..423500d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,7 +17,7 @@ jobs: with: node-version: '20.x' - name: Install dependencies - run: npm run build + run: node -v - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: From f9bb1081aca16b50245f4681931d58ffd7c9313f Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:42:21 +0530 Subject: [PATCH 23/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 423500d..5621594 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -15,7 +15,7 @@ jobs: - name: Use Node.js uses: actions/setup-node@v3 with: - node-version: '20.x' + node-version: '21.x' - name: Install dependencies run: node -v - name: Run Tests From b467ba162028a30d6de001909b7eb65cb7cb6e78 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:43:28 +0530 Subject: [PATCH 24/28] modified run-tests.yml --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5621594..74e3265 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -17,7 +17,7 @@ jobs: with: node-version: '21.x' - name: Install dependencies - run: node -v + run: npm install - name: Run Tests run: CLIENT_ID=$PG_CLIENT_ID SECRET_KEY=$PG_CLIENT_SECRET npm test env: From fc51d03dc008df01008d34abdf2c21f26e0abee8 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:45:14 +0530 Subject: [PATCH 25/28] modified run-tests.yml --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 91660ee..19657a7 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "devDependencies": { "@types/chai": "^4.3.10", "@types/jest": "^29.5.10", - "@types/node": "^12.11.5", + "@types/node": "^12.20.55", "@types/sinon": "^17.0.1", "chai": "^4.3.10", "jest": "^29.7.0", @@ -40,4 +40,4 @@ "ts-jest": "^29.1.1", "typescript": "^4.9.5" } -} \ No newline at end of file +} From 38bfcd066d572281da2341051c9d08dd48019238 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 15:47:05 +0530 Subject: [PATCH 26/28] modified run-tests.yml --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 19657a7..de8a432 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/chai": "^4.3.10", "@types/jest": "^29.5.10", "@types/node": "^12.20.55", + "@types/react": "^18.2.39", "@types/sinon": "^17.0.1", "chai": "^4.3.10", "jest": "^29.7.0", From 1f6d5a592f936c3b8f0b91fefb0701410b1347de Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 18:04:50 +0530 Subject: [PATCH 27/28] modified --- tests/orders.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/orders.test.ts b/tests/orders.test.ts index 3258177..64a5a71 100644 --- a/tests/orders.test.ts +++ b/tests/orders.test.ts @@ -44,7 +44,7 @@ it('Create Order Test', function (done) { Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { assert.equal(response.data.order_amount, request.order_amount, "Amount is not matching") - assert.equal(response.data.order_currency, "INR", "Currency is not matching") + assert.equal(response.data.order_currency, "INRs", "Currency is not matching") assert.equal(response.data.customer_details?.customer_id, response.data.customer_details?.customer_id, "Customer id is not matching") assert.equal(response.data.customer_details?.customer_name, response.data.customer_details?.customer_name, "Customer name is not matching") assert.equal(response.data.customer_details?.customer_email, response.data.customer_details?.customer_email, "Customer email is not matching") From 171d047c820846f2b658aa90a3dc88d53f7e62c2 Mon Sep 17 00:00:00 2001 From: Venkata Pranav Date: Tue, 28 Nov 2023 18:06:32 +0530 Subject: [PATCH 28/28] modified --- tests/orders.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/orders.test.ts b/tests/orders.test.ts index 64a5a71..3258177 100644 --- a/tests/orders.test.ts +++ b/tests/orders.test.ts @@ -44,7 +44,7 @@ it('Create Order Test', function (done) { Cashfree.PGCreateOrder("2022-09-01", request).then((response) => { assert.equal(response.data.order_amount, request.order_amount, "Amount is not matching") - assert.equal(response.data.order_currency, "INRs", "Currency is not matching") + assert.equal(response.data.order_currency, "INR", "Currency is not matching") assert.equal(response.data.customer_details?.customer_id, response.data.customer_details?.customer_id, "Customer id is not matching") assert.equal(response.data.customer_details?.customer_name, response.data.customer_details?.customer_name, "Customer name is not matching") assert.equal(response.data.customer_details?.customer_email, response.data.customer_details?.customer_email, "Customer email is not matching")