Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2e test token account #363

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
34 changes: 34 additions & 0 deletions .github/workflows/prod_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 env -- mocha --timeout 10000 --recursive --require babel-register test_prod/
env:
API_KEY: ${{ secrets.API_KEY }}
API_SECRET: ${{ secrets.API_SECRET }}
PRODUCT_API_KEY: ${{ secrets.PRODUCT_API_KEY }}
PRODUCT_API_SECRET: ${{ secrets.PRODUCT_API_SECRET }}
25 changes: 25 additions & 0 deletions test_prod/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const Razorpay = require("../dist/razorpay");
let request = require('request-promise');

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.PRODUCT_API_KEY || "",
key_secret: process.env.PRODUCT_API_SECRET || "",
hostUrl : "https://api-web.dev.razorpay.in"
});
25 changes: 25 additions & 0 deletions test_prod/razorpay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const Razorpay = require("../dist/razorpay");
let request = require('request-promise');

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 || "",
hostUrl : "https://api-web.dev.razorpay.in"
});
152 changes: 152 additions & 0 deletions test_prod/resources/account.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
'use strict'

var assert = require('assert');
const rzpInstance = require('../product')
const path = require('path')
const fs = require('fs');
let skipDoc = true;

let accountId = null;
let setAccount = {
"email": `gauriagain.kumar_${Math.floor(Date.now() / 1000)}@example.org`,
"phone": "9000090000",
"legal_business_name": "Acme Corp",
"business_type": "partnership",
"customer_facing_business_name": "Example",
"profile": {
"category": "healthcare",
"subcategory": "clinic",
"description": "Healthcare E-commerce platform",
"addresses": {
"operation": {
"street1": "507, Koramangala 6th block",
"street2": "Kormanagala",
"city": "Bengaluru",
"state": "Karnataka",
"postal_code": 560047,
"country": "IN"
},
"registered": {
"street1": "507, Koramangala 1st block",
"street2": "MG Road",
"city": "Bengaluru",
"state": "Karnataka",
"postal_code": 560034,
"country": "IN"
}
},
"business_model": "Online Clothing ( men, women, ethnic, modern ) fashion and lifestyle, accessories, t-shirt, shirt, track pant, shoes."
},
"legal_info": {
"pan": "AAACL1234C",
"gst": "18AABCU9603R1ZM"
},
"brand": {
"color": "FFFFFF"
},
"notes": {
"internal_ref_id": "123123"
},
"contact_name": "Gaurav Kumar",
"contact_info": {
"chargeback": {
"email": "[email protected]"
},
"refund": {
"email": "[email protected]"
},
"support": {
"email": "[email protected]",
"phone": "9999999998",
"policy_url": "https://www.google.com"
}
},
"apps": {
"websites": [
"https://www.example.org"
],
"android": [
{
"url": "playstore.example.org",
"name": "Example"
}
],
"ios": [
{
"url": "appstore.example.org",
"name": "Example"
}
]
}
}

describe('ACCOUNTS', () => {

it('create account', (done) => {

rzpInstance.accounts.create(setAccount)
.then((response) => {
accountId = response.id
assert.ok(response.hasOwnProperty('id'))
assert.ok(response.hasOwnProperty('type'))
done()
}).catch(err => console.log(err))

})

it('fetch account by id', (done) => {
rzpInstance.accounts.fetch(accountId).then((response) => {
assert.ok(response.hasOwnProperty('id'))
assert.ok((response.id === accountId))
done()
}).catch(err => console.log(err))
})

it('document upload token', (done) => {

rzpInstance.accounts.uploadAccountDoc(accountId, {
'file': {
'value': fs.createReadStream(path.resolve(__dirname, `dummy.pdf`)),
'options': {
'filename': 'dummy.pdf',
'contentType': null
}
},
'document_type': 'business_proof_url'
})
.then(response => {
skipDoc = false
assert.ok(response.hasOwnProperty('business_proof_of_identification'))
done()
}).catch(err => {
if(err.hasOwnProperty('error'))
{
if(err.error.reason == 'NA'){
console.warn('server issue')
done()
}
}
})

})

it('fetch documents', (done) => {
rzpInstance.accounts.fetchAccountDoc(accountId).then((response) => {
if(skipDoc){
assert.ok((typeof response == 'object'))
}else{
assert.ok(response.hasOwnProperty('business_proof_of_identification'))
}

done()
}).catch(err => console.log(err))
})

it('delete token', (done) => {
rzpInstance.accounts.delete(accountId).then((response) => {
assert.ok((response.id === accountId))
assert.ok(response.hasOwnProperty('id'))
done()
}).catch(err => console.log(err))
})
})
Binary file added test_prod/resources/dummy.pdf
Binary file not shown.
66 changes: 66 additions & 0 deletions test_prod/resources/tokens.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict'

var assert = require('assert');
const rzpInstance = require('../razorpay')

let tokenId = null;
let customerId = null;

describe('TOKENS', () => {

it('create token account', (done) => {

rzpInstance.customers.create({
"name": "Gaurav Kumar",
"contact": 9123456780,
"email": "[email protected]",
"fail_existing": 0,
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
}
}).then(response=>{
customerId = response.id
return customerId
}).then((id)=>{
rzpInstance.tokens.create({
"customer_id": id,
"method": "card",
"card": {
"number": "4854980604708430",
"cvv": "123",
"expiry_month": "12",
"expiry_year": "24"
},
"authentication": {
"provider": "razorpay",
"provider_reference_id": "pay_123wkejnsakd"
},
"notes": []
}).then((response) => {
tokenId = response.id
assert.ok(response.hasOwnProperty('id'))
assert.ok(response.hasOwnProperty('entity'))
done()
}).catch(err => console.log(err))
}).catch(err => console.log(err))
})

it('fetch tokens', (done) => {
rzpInstance.tokens.fetch({ id: tokenId }).then((response) => {
assert.ok(response.hasOwnProperty('id'))
assert.ok(response.hasOwnProperty('entity'))
assert.ok((response.id === tokenId))
done()
}).catch(err => console.log(err))
})

it('delete token', (done) => {
rzpInstance.tokens.delete({
id : tokenId
}).then((response) => {
assert.ok((typeof response == 'object'))
done()
}).catch(err => console.log(err))
})
})