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 plans items #359

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/prod_ci.yml
Original file line number Diff line number Diff line change
@@ -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 env -- mocha --timeout 10000 --recursive --require babel-register test_prod/
env:
API_KEY: ${{ secrets.API_KEY }}
API_SECRET: ${{ secrets.API_SECRET }}
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"
});
64 changes: 64 additions & 0 deletions test_prod/resources/items.spec.js
Original file line number Diff line number Diff line change
@@ -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))
})
})
51 changes: 51 additions & 0 deletions test_prod/resources/plans.spec.js
Original file line number Diff line number Diff line change
@@ -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))
})
})