Best JavaScript code snippet using ava
payments.js
Source:payments.js
1var test = require('ava')2var indy = require('../')3var cuid = require('cuid')4var initTestPool = require('./helpers/initTestPool')5test('payments', async function (t) {6 var pool = await initTestPool()7 var walletConfig = { 'id': 'wallet-' + cuid() }8 var walletCredentials = { 'key': 'key' }9 await indy.createWallet(walletConfig, walletCredentials)10 var wh = await indy.openWallet(walletConfig, walletCredentials)11 var [trusteeDid] = await indy.createAndStoreMyDid(wh, { seed: '000000000000000000000000Trustee1' })12 var paymentMethod = 'null'13 var paymentAddress = 'pay:null:test'14 var inputs = ['pay:null:1']15 var outputs = [{ 'recipient': 'pay:null:1', 'amount': 1 }]16 var from = 117 var err = await t.throwsAsync(indy.createPaymentAddress(wh, paymentMethod, {}))18 t.is(err.indyName, 'PaymentUnknownMethodError')19 t.deepEqual(await indy.listPaymentAddresses(wh), [])20 err = await t.throwsAsync(indy.addRequestFees(wh, trusteeDid, {}, inputs, outputs, null))21 t.is(err.indyName, 'PaymentUnknownMethodError')22 err = await t.throwsAsync(indy.parseResponseWithFees(paymentMethod, {}))23 t.is(err.indyName, 'PaymentUnknownMethodError')24 err = await t.throwsAsync(indy.buildGetPaymentSourcesRequest(wh, trusteeDid, paymentAddress))25 t.is(err.indyName, 'PaymentUnknownMethodError')26 err = await t.throwsAsync(indy.buildGetPaymentSourcesWithFromRequest(wh, trusteeDid, paymentAddress, from))27 t.is(err.indyName, 'PaymentUnknownMethodError')28 err = await t.throwsAsync(indy.parseGetPaymentSourcesWithFromResponse(paymentMethod, {}))29 t.is(err.indyName, 'PaymentUnknownMethodError')30 err = await t.throwsAsync(indy.buildPaymentReq(wh, trusteeDid, inputs, outputs, null))31 t.is(err.indyName, 'PaymentUnknownMethodError')32 err = await t.throwsAsync(indy.parsePaymentResponse(paymentMethod, {}))33 t.is(err.indyName, 'PaymentUnknownMethodError')34 var extra = await indy.preparePaymentExtraWithAcceptanceData(null, 'indy agreement', '1.0.0', null, 'acceptance mechanism label 1', 123379200)35 var expectedExtra = {36 'mechanism': 'acceptance mechanism label 1',37 'taaDigest': '7213b9aabf8677edf6b17d20a9fbfaddb059ea4cb122d163bdf658ea67196120',38 'time': 12337920039 }40 t.deepEqual(extra['taaAcceptance'], expectedExtra)41 err = await t.throwsAsync(indy.buildMintReq(wh, trusteeDid, outputs, null))42 t.is(err.indyName, 'PaymentUnknownMethodError')43 var fees = { 'txnType1': 1, 'txnType2': 2 }44 err = await t.throwsAsync(indy.buildSetTxnFeesReq(wh, trusteeDid, paymentMethod, fees))45 t.is(err.indyName, 'PaymentUnknownMethodError')46 err = await t.throwsAsync(indy.buildGetTxnFeesReq(wh, trusteeDid, paymentMethod))47 t.is(err.indyName, 'PaymentUnknownMethodError')48 err = await t.throwsAsync(indy.parseGetTxnFeesResponse(paymentMethod, {}))49 t.is(err.indyName, 'PaymentUnknownMethodError')50 var receipt = 'pay:null:0_PqVjwJC42sxCTJp'51 err = await t.throwsAsync(indy.buildVerifyPaymentReq(wh, trusteeDid, receipt))52 t.is(err.indyName, 'PaymentUnknownMethodError')53 err = await t.throwsAsync(indy.parseVerifyPaymentResponse(paymentMethod, {}))54 t.is(err.indyName, 'PaymentUnknownMethodError')55 var message = Buffer.from('123456789', 'utf8')56 err = await t.throwsAsync(indy.signWithAddress(wh, paymentAddress, message))57 t.is(err.indyName, 'PaymentUnknownMethodError')58 var signature = Buffer.from('987654321', 'utf8')59 err = await t.throwsAsync(indy.verifyWithAddress(paymentAddress, message, signature))60 t.is(err.indyName, 'PaymentUnknownMethodError')61 var getAuthRuleResp = { 'result': { 'data': [ { 'new_value': '0', 'constraint': { 'need_to_be_owner': false, 'sig_count': 1, 'metadata': { 'fees': '1' }, 'role': '0', 'constraint_id': 'ROLE' }, 'field': 'role', 'auth_type': '1', 'auth_action': 'ADD' } ], 'identifier': 'LibindyDid111111111111', 'auth_action': 'ADD', 'new_value': '0', 'reqId': 15616, 'auth_type': '1', 'type': '121', 'field': 'role' }, 'op': 'REPLY' }62 var requesterInfo = { 'role': '0', 'need_to_be_owner': false, 'sig_count': 1 }63 fees = { '1': 100 }64 var requestInfo = await indy.getRequestInfo(getAuthRuleResp, requesterInfo, fees)65 var expectedRequestInfo = {66 'price': 100,67 'requirements': [{68 'role': '0',69 'need_to_be_owner': false,70 'sig_count': 171 }]72 }73 t.deepEqual(expectedRequestInfo, requestInfo)74 await indy.closeWallet(wh)75 await indy.deleteWallet(walletConfig, walletCredentials)76 pool.cleanup()...
Using AI Code Generation
1const test = require('ava');2test('throws async', async t => {3 await t.throwsAsync(Promise.reject(new Error('foo')));4 await t.throwsAsync(Promise.reject(new Error('foo')), 'foo');5 await t.throwsAsync(Promise.reject(new Error('foo')), /foo/);6 await t.throwsAsync(Promise.reject(new Error('foo')), {instanceOf: Error, message: 'foo'});7});8const test = require('ava');9test('not throws async', async t => {10 await t.notThrowsAsync(Promise.resolve());11});
Using AI Code Generation
1import test from 'ava';2import delay from 'delay';3import fn from './';4test('main', async t => {5 const err = await t.throwsAsync(fn(), 'foo');6 t.is(err.message, 'foo');7 t.true(delay.called);8});
Using AI Code Generation
1const test = require('ava')2const { throwsAsync } = require('assert')3const { read } = require('./file')4test('read() should throw an error if the file does not exist', async t => {5 const error = await throwsAsync(read('non-existent.txt'), /no such file or directory/i)6 t.is(error.code, 'ENOENT')7})8const { readFile } = require('fs')9const { promisify } = require('util')10const read = promisify(readFile)11module.exports = { read }12const test = require('ava')13const { read } = require('./file')14test('read() should throw an error if the file does not exist', t => {15 return read('non-existent.txt')16 .then(() => {17 t.fail('Promise should reject')18 })19 .catch(error => {20 t.is(error.code, 'ENOENT')21 })22})23const { readFile } = require('fs')24const { promisify } = require('util')25const read = promisify(readFile)26module.exports = { read }27const test = require('ava')28const { read } = require('./file')29test('read() should throw an error if the file does not exist', async t => {30 await t.throwsAsync(read('non-existent.txt'), { code: 'ENOENT' })31})32const { readFile } = require('fs')33const { promisify } = require('util')34const read = promisify(readFile)35module.exports = { read }36const test = require('ava')37const { read } = require('./file')38test('read() should throw an error if the file does not exist', async t => {39 await t.throwsAsync(read('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!