How to use persistedAccount method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

account.acceptance.ts

Source:account.acceptance.ts Github

copy

Full Screen

1// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.2// Node module: @loopback/example-references-many3// This file is licensed under the MIT License.4// License text available at https://opensource.org/licenses/MIT5import {EntityNotFoundError} from '@loopback/repository';6import {Client, createRestAppClient, expect, toJSON} from '@loopback/testlab';7import {ReferencesManyApplication} from '../../application';8import {Account} from '../../models/';9import {AccountRepository} from '../../repositories/';10import {11 givenAccount,12 givenAccountInstance,13 givenAccountRepositories,14 givenRunningApplicationWithCustomConfiguration,15} from '../helpers';16describe('ReferencesManyApplication', () => {17 let app: ReferencesManyApplication;18 let client: Client;19 let accountRepo: AccountRepository;20 before(async () => {21 app = await givenRunningApplicationWithCustomConfiguration();22 });23 after(() => app.stop());24 before(async () => {25 ({accountRepo} = await givenAccountRepositories(app));26 });27 before(() => {28 client = createRestAppClient(app);29 });30 beforeEach(async () => {31 await accountRepo.deleteAll();32 });33 it('creates an account', async function () {34 const account = givenAccount();35 const response = await client.post('/accounts').send(account).expect(200);36 expect(response.body).to.containDeep(account);37 const result = await accountRepo.findById(response.body.id);38 expect(result).to.containDeep(account);39 });40 it('gets a count of accounts', async function () {41 await givenAccountInstance(accountRepo, {balance: 22});42 await givenAccountInstance(accountRepo, {balance: 33});43 await client.get('/accounts/count').expect(200, {count: 2});44 });45 context('when dealing with a single persisted account', () => {46 let persistedAccount: Account;47 beforeEach(async () => {48 persistedAccount = await givenAccountInstance(accountRepo);49 });50 it('gets an account by ID', () => {51 return client52 .get(`/accounts/${persistedAccount.id}`)53 .send()54 .expect(200, toJSON(persistedAccount));55 });56 it('returns 404 when getting an account that does not exist', () => {57 return client.get('/accounts/99999').expect(404);58 });59 it('replaces the account by ID', async () => {60 const updatedAccount = givenAccount({61 balance: 44,62 });63 await client64 .put(`/accounts/${persistedAccount.id}`)65 .send(updatedAccount)66 .expect(204);67 const result = await accountRepo.findById(persistedAccount.id);68 expect(result).to.containEql(updatedAccount);69 });70 it('returns 404 when replacing an account that does not exist', () => {71 return client.put('/accounts/99999').send(givenAccount()).expect(404);72 });73 it('updates the account by ID ', async () => {74 const updatedAccount = givenAccount({75 balance: 55,76 });77 await client78 .patch(`/accounts/${persistedAccount.id}`)79 .send(updatedAccount)80 .expect(204);81 const result = await accountRepo.findById(persistedAccount.id);82 expect(result).to.containEql(updatedAccount);83 });84 it('returns 404 when updating an account that does not exist', () => {85 return client.patch('/account/99999').send(givenAccount()).expect(404);86 });87 it('deletes the account', async () => {88 await client.del(`/accounts/${persistedAccount.id}`).send().expect(204);89 await expect(90 accountRepo.findById(persistedAccount.id),91 ).to.be.rejectedWith(EntityNotFoundError);92 });93 it('returns 404 when deleting an account that does not exist', async () => {94 await client.del(`/accounts/99999`).expect(404);95 });96 });97 it('queries accounts with a filter', async () => {98 await givenAccountInstance(accountRepo, {balance: 77});99 const emptyAccount = await givenAccountInstance(accountRepo, {balance: 0});100 await client101 .get('/accounts')102 .query({filter: {where: {balance: 0}}})103 .expect(200, [toJSON(emptyAccount)]);104 });105 it('updates accounts using a filter', async () => {106 await givenAccountInstance(accountRepo, {107 balance: 1,108 });109 await givenAccountInstance(accountRepo, {110 balance: 2,111 });112 await client113 .patch('/accounts')114 .query({where: {balance: 2}})115 .send({balance: 3})116 .expect(200, {count: 1});117 });...

Full Screen

Full Screen

testAuthentication.js

Source:testAuthentication.js Github

copy

Full Screen

1import Account from '../../../src/accounts/entities/Account';2import AccountRepository from '../../../src/accounts/entities/Repository';3import SecurityUseCases from '../../../src/accounts/useCases/Security';4import SecurityContract from '../../../src/accounts/useCases/SecurityContract';5import EncryptionService from '../../../src/accounts/entities/Encryption'; 6import sinon from 'sinon';7import 'should';8import should from 'should';9describe('Authenticate Account Use Case', function () {10 let mockUserRepository;11 let persistedAccount;12 let mockEncryptionService;13 let mockTokenManager;14 let token;15 let encryptedPassword;16 beforeEach(() => {17 sinon.restore();18 mockUserRepository = new AccountRepository();19 mockTokenManager = new SecurityContract();20 token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'21 encryptedPassword = 'goobledegook'22 persistedAccount = new Account('123', 'John', 'Doe', 'john.doe@email.com', 'tester');23 // persistedAccounts = [new Account(123, 'John', 'Doe', 'john.doe@email.com', 'tester'), new Account(456, 'Jane', 'Doe', 'jane.doe@email.com', 'tester')];24 mockEncryptionService = new EncryptionService();25 });26 it('should return a token', async function () {27 const findByEmail = sinon.stub(mockUserRepository, 'getByEmail').resolves(persistedAccount);28 sinon.stub(mockTokenManager, 'generate').resolves(token);29 sinon.stub(mockEncryptionService, 'compare').returns(true);30 const result = await SecurityUseCases.authenticate(persistedAccount.email, persistedAccount.password, mockUserRepository, mockTokenManager, mockEncryptionService);31 result.should.equal(token);32 sinon.assert.calledWith(findByEmail, 'john.doe@email.com');33 });34 it('should reject authentication', async function () {35 sinon.stub(mockUserRepository, 'getByEmail').resolves(persistedAccount);36 sinon.stub(mockTokenManager, 'generate').resolves(token);37 sinon.stub(mockEncryptionService, 'compare').returns(false);38 try{39 await SecurityUseCases.authenticate(persistedAccount.email, persistedAccount.password, mockUserRepository, mockTokenManager, mockEncryptionService)40 }catch(error){41 error.exist;42 }43 });44 it('should verify a token', async function () {45 sinon.stub(mockUserRepository, 'getByEmail').resolves(persistedAccount);46 const decode = sinon.stub(mockTokenManager, 'decode').resolves(persistedAccount.email);47 const result = await SecurityUseCases.verify(token, mockUserRepository,mockTokenManager );48 result.should.equal(persistedAccount.email);49 sinon.assert.calledWith(decode, token);50 });...

Full Screen

Full Screen

testCreateAccount.js

Source:testCreateAccount.js Github

copy

Full Screen

1import Account from '../../../src/accounts/entities/Account';2import AccountRepository from '../../../src/accounts/entities/Repository';3import EncryptionService from '../../../src/accounts/entities/Encryption';4import AccountUseCases from '../../../src/accounts/useCases/Account';5import sinon from 'sinon';6import 'should';7describe('Create Account Use Case', function () {8 let persistedAccount;9 let persistedAccounts;10 let services;11 let encryptedPassword;12 let password;13 beforeEach(() => {14 sinon.restore();15 services = {16 accountsRepository: new AccountRepository(),17 encryptionService: new EncryptionService()18 }19 encryptedPassword = 'goobledegook';20 password = 'tester';21 persistedAccount = new Account('123', 'John', 'Doe', 'john.doe@email.com');22 persistedAccounts = [new Account('123', 'John', 'Doe', 'john.doe@email.com', 'tester'), new Account('456', 'Jane', 'Doe', 'jane.doe@email.com', 'tester')];23 });24 it('should resolve with the newly persisted account (augmented with an ID)', async function () {25 const persist = sinon.stub(services.accountsRepository, 'persist').resolves(persistedAccount);26 sinon.stub(services.encryptionService, 'encrypt').returns(encryptedPassword);27 const account = await AccountUseCases.registerAccount('John', 'Doe', 'john.doe@email.com', password, services);28 account.should.equal(persistedAccount);29 sinon.assert.calledWith(persist, new Account(undefined, 'John', 'Doe', 'john.doe@email.com', encryptedPassword));30 });31 it('should find all accountns', async function () {32 sinon.stub(services.accountsRepository, 'find').resolves(persistedAccounts);33 const accounts = await AccountUseCases.find(services);34 accounts.length.should.equal(2);35 });36 it('should update an account details', async function () {37 const merge = sinon.stub(services.accountsRepository, 'merge').resolves(persistedAccount);38 sinon.stub(services.encryptionService, 'encrypt').returns(encryptedPassword);39 const account = await AccountUseCases.updateAccount('123', 'John', 'Doe', 'john.doe@email.com', 'tester', services);40 account.should.equal(persistedAccount);41 sinon.assert.calledWith(merge, new Account(persistedAccount.id, 'John', 'Doe', 'john.doe@email.com', 'tester'));42 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const mockServer = require('pact-foundation-pact-node');2const opts = {3 log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),4 dir: path.resolve(process.cwd(), 'pacts'),5};6 .mockServer(opts)7 .then(function (server) {8 console.log('Server started');9 console.log('Pact File Written');10 server.delete();11 })12 .catch(function (e) {13 console.log('Error: ', e);14 });15Error: { Error: connect ECONNREFUSED

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Pact } from '@pact-foundation/pact'2import { Matchers } from '@pact-foundation/pact/dsl/matchers'3import { pactWith } from 'jest-pact'4import { getTodos } from '../src/client'5const pact = Pact.persistedAccount('pact-test-account')6describe('Todo API', () => {7 describe('get todos', () => {8 beforeAll(() => {9 return pact.setup()10 })11 test('returns a list of todos', async () => {12 await pact.addInteraction({13 withRequest: {14 headers: {15 },16 },17 willRespondWith: {18 body: Matchers.eachLike({19 id: Matchers.somethingLike(1),20 title: Matchers.somethingLike('Buy milk'),21 completed: Matchers.somethingLike(false),22 }),23 headers: {24 'Content-Type': 'application/json; charset=utf-8',25 },26 },27 })28 const response = await getTodos(pact.mockService.baseUrl)29 expect(response.status).toEqual(200)30 expect(response.data).toEqual([31 { id: 1, title: 'Buy milk', completed: false },32 })33 afterAll(() => {34 return pact.finalize()35 })36 })37})38import { Pact } from '@pact-foundation/pact'39import { Matchers } from '@pact-foundation/pact/dsl/matchers'40import { pactWith } from 'jest

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful