How to use willRespondWith method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

pact.test.js

Source:pact.test.js Github

copy

Full Screen

1import Pact, {Matchers} from 'pact'2import path from 'path'3import {get} from './lib/http'4import {post} from './lib/http'5describe('set up pact', () => {6 const PACT_SERVER_PORT = 124007 const PACT_SPECIFICATION_VERSION = 28 const PACT_HOST = 'http://localhost:' + PACT_SERVER_PORT9 const provider = Pact({10 consumer: 'Frontend',11 provider: 'Backend',12 port: PACT_SERVER_PORT,13 spec: PACT_SPECIFICATION_VERSION,14 log: path.resolve(process.cwd(), './__pacts__/logs', 'pact-integration.log'),15 dir: path.resolve(process.cwd(), './__pacts__/pacts')16 })17 beforeAll(() => provider.setup())18 afterAll(() => provider.finalize())19 describe('returns a welcome message', () => {20 const expected = {message: 'Welcome to backend API!'}21 beforeAll(() => provider.addInteraction({22 uponReceiving: 'a request for getting welcome message',23 withRequest: {24 method: 'GET',25 path: '/api',26 headers: { 'Accept': 'application/json' }27 },28 willRespondWith: {29 status: 200,30 headers: { 'Content-Type': 'application/json; charset=utf-8' },31 body: expected32 }33 })34 )35 36 it('returns a list of events', async () => {37 const result = await get(PACT_HOST + '/api', {headers: { 'Accept': 'application/json' }})38 39 expect(result).toEqual({...expected, status: 200})40 })41 it('successfully verifies', () => provider.verify())42 })43 // Forum44 describe('returns a forum thread', () => {45 46 const headers = {47 'Accept': 'application/json',48 'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIxIiwiZW1haWwiOiJ1c2VyMUB1c2VyLmNvbSIsInJvbGUiOiJVU0VSIiwidXNlcklkIjoiNWEzMjY1ZTM3YTdkNTUwMDFkOGEyZTZlIn0.ikrvRAg6kTZItYXzxC0CyBSrGXryxTp95QUvQI9nYGI'49 };50 beforeAll(() => provider.addInteraction({51 uponReceiving: 'returns a forum thread',52 withRequest: {53 method: 'GET',54 path: '/api/forum/thread',55 headers: headers56 },57 willRespondWith: {58 status: 200,59 headers: { 'Content-Type': 'application/json; charset=utf-8' },60 body: Matchers.eachLike(61 {62 "title": "How to configure the flux capasitor in a Samsung 420? thread 0 . 0",63 "date": "2017-12-18T12:44:45.028Z"64 }65 )66 }67 })68 )69 70 it('returns a forum thread', async () => {71 const result = await get(PACT_HOST + '/api/forum/thread', {headers: headers})72 73 const expected = [74 {75 "title": "How to configure the flux capasitor in a Samsung 420? thread 0 . 0",76 "date": "2017-12-18T12:44:45.028Z"77 }78 ]79 expected.status = 20080 expect(result).toEqual(expected)81 })82 it('successfully verifies', () => provider.verify())83 })84 // LOGIN TESTS85 describe('admin can login in', () => {86 const expected = {87 error: false,88 token: 'eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJBZG1pbiIsImVtYWlsIjoiYWRtaW5AYWRtaW4ubnUiLCJyb2xlIjoiQURNSU4ifQ.jcQEXVDj3HZADGaLRRCAIRpLr7anqmWY-J6Ms9yUdgE'89 }90 beforeAll(() => provider.addInteraction({91 uponReceiving: 'login request with admin login',92 withRequest: {93 method: 'POST',94 path: '/api/user/login',95 headers: {96 'Content-Type': 'application/json'97 },98 body: { 'email': 'admin@admin.nu', 'password': 'admin' }99 },100 willRespondWith: {101 status: 200,102 headers: { 'Content-Type': 'application/json; charset=utf-8' },103 body: {104 error: false,105 token: Matchers.somethingLike('eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJBZG1pbiIsImVtYWlsIjoiYWRtaW5AYWRtaW4ubnUiLCJyb2xlIjoiQURNSU4ifQ.jcQEXVDj3HZADGaLRRCAIRpLr7anqmWY-J6Ms9yUdgE')106 }107 }108 })109 )110 it('returns a matching token', async () => {111 const result = await post(PACT_HOST + '/api/user/login', {headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({email: 'admin@admin.nu', password: 'admin'})})112 expect(result).toEqual({...expected, status: 200})113 })114 it('successfully verifies', () => provider.verify())115 })116 117 describe('company rep can login in', () => {118 const expected = { error: false, token: "eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTlNhbXN1bmdSZXAiLCJlbWFpbCI6InJlcEBzYW1zdW5nLmNvbSIsInJvbGUiOiJDT01QQU5ZX1JFUCIsImNvbXBhbnlJZCI6IjVhNGI1MWJlZWJlYThiMDAyOTRhYzkzYSJ9.amXegC52E3M1F3A4P90FOtFYJBNEz_Ot9gyvqr3YCho" }119 beforeAll(() => provider.addInteraction({120 uponReceiving: 'login request with company rep login',121 withRequest: {122 method: 'POST',123 path: '/api/user/login',124 headers: { 'Content-Type': 'application/json' },125 body: { 'email': 'rep@samsung.com', 'password': 'password' }126 },127 willRespondWith: {128 status: 200,129 headers: { 'Content-Type': 'application/json; charset=utf-8' },130 body: {131 error: false,132 token: Matchers.somethingLike('eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTlNhbXN1bmdSZXAiLCJlbWFpbCI6InJlcEBzYW1zdW5nLmNvbSIsInJvbGUiOiJDT01QQU5ZX1JFUCIsImNvbXBhbnlJZCI6IjVhNGI1MWJlZWJlYThiMDAyOTRhYzkzYSJ9.amXegC52E3M1F3A4P90FOtFYJBNEz_Ot9gyvqr3YCho')133 }134 }135 })136 )137 it('returns a matching token', async () => {138 const result = await post(PACT_HOST + '/api/user/login', {headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({email: 'rep@samsung.com', password: "password"})})139 expect(result).toEqual({...expected, status: 200})140 })141 })142 describe('user can login in', () => {143 const expected = { error: false, token: "eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIyOSIsImVtYWlsIjoidXNlcjI5QHVzZXIuY29tIiwicm9sZSI6IlVTRVIifQ.w2_IERnUUMbnSeGHSjNv0CMIEC-YSA4UMksRXdv5g-8" }144 beforeAll(() => provider.addInteraction({145 uponReceiving: 'login request with regular user login',146 withRequest: {147 method: 'POST',148 path: '/api/user/login',149 headers: { 'Content-Type': 'application/json' },150 body: { 'email': 'user29@user.com', 'password': 'password' }151 },152 willRespondWith: {153 status: 200,154 headers: { 'Content-Type': 'application/json; charset=utf-8' },155 body: {156 error: false,157 token: Matchers.somethingLike('eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIyOSIsImVtYWlsIjoidXNlcjI5QHVzZXIuY29tIiwicm9sZSI6IlVTRVIifQ.w2_IERnUUMbnSeGHSjNv0CMIEC-YSA4UMksRXdv5g-8')158 }159 }160 })161 )162 it('returns a matching token', async () => {163 const result = await post(PACT_HOST + '/api/user/login', {headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({email: 'user29@user.com', password: "password"})})164 expect(result).toEqual({...expected, status: 200})165 })166 })167// TEST 2 START168 describe('returns all products', () => {169 const headers = {170 'Accept': 'application/json',171 'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIyOSIsImVtYWlsIjoidXNlcjI5QHVzZXIuY29tIiwicm9sZSI6IlVTRVIifQ.w2_IERnUUMbnSeGHSjNv0CMIEC-YSA4UMksRXdv5g-8'172 }173 beforeAll(() => provider.addInteraction({174 uponReceiving: 'a request for getting products',175 withRequest: {176 method: 'GET',177 path: '/api/product',178 headers179 },180 willRespondWith: {181 status: 200,182 headers: { 'Content-Type': 'application/json; charset=utf-8' },183 body: Matchers.eachLike({184 "_id": "5a280388169758001ce1fd6b",185 "name": "Samsung Mobile Phone 0",186 "category": "5a280387169758001ce1fd5f",187 "rating": [],188 "materials": ["5a280388169758001ce1fd69"]189 })190 }191 })192 )193 it('returns a list of events', async () => {194 const result = await get(PACT_HOST + '/api/product', {headers})195 const expected = [196 {197 "_id": "5a280388169758001ce1fd6b",198 "name": "Samsung Mobile Phone 0",199 "category": "5a280387169758001ce1fd5f",200 "rating": [],201 "materials": ["5a280388169758001ce1fd69"]202 }203 ]204 expected.status = 200 // fix for ugly mapping of response status205 expect(result).toEqual(expected)206 })207 it('successfully verifies', () => provider.verify())208 })209// TEST 2 END210 describe('returns an error if no token in header on auth route', () => {211 const expected = {message: 'There was no token in the header', error: true }212 beforeAll(() => provider.addInteraction({213 uponReceiving: 'a request without auth header on authed route',214 withRequest: {215 method: 'GET',216 path: '/api/user/products',217 headers: { 'Accept': 'application/json' }218 },219 willRespondWith: {220 status: 401,221 headers: { 'Content-Type': 'application/json; charset=utf-8' },222 body: expected223 }224 })225 )226 it('returns an error', async () => {227 const result = await get(PACT_HOST + '/api/user/products', {headers: { 'Accept': 'application/json' }})228 expect(result).toEqual({...expected, status: 401})229 })230 })231 /*232 // Testing Rating233 describe('Create a rating', () => {234 const headers = {235 'Content-Type': 'application/json',236 'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIyOSIsImVtYWlsIjoidXNlcjI5QHVzZXIuY29tIiwicm9sZSI6IlVTRVIifQ.w2_IERnUUMbnSeGHSjNv0CMIEC-YSA4UMksRXdv5g-8'237 };238 239 beforeAll(() => provider.addInteraction({240 uponReceiving: 'a request for creating a rating',241 withRequest: {242 method: 'POST',243 path: '/api/product/material/5a2838e4407de3001da76d72/rating',244 headers,245 body: { 'rating': 4 }246 },247 willRespondWith: {248 status: 201,249 headers: { 'Content-Type': 'application/json; charset=utf-8' },250 body: {251 "_id": "5a2838e4407de3001da76d72",252 "name": "manual",253 "originalname": "components.pdf",254 "filename": "e506a9172af9259843342dc44c58f763",255 "path": "src/lib/seed/e506a9172af9259843342dc44c58f763",256 "size": 33600,257 "mimetype": "application/pdf",258 "__v": 2,259 "avgRating": 4,260 "rating": [261 {262 "_id": "5a283ba1e892b9001e44fd6e",263 "userid": "5a2838d7407de3001da76d00",264 "materialid": "5a2838e4407de3001da76d72",265 "rating": 4266 },267 {268 "_id": "5a2846614bd89f001ee98d36",269 "userid": "5a2838d7407de3001da76d1e",270 "materialid": "5a2838e4407de3001da76d72",271 "rating": 4272 }273 ]274 }275 }276 })277 );278 const expected = {279 "_id": "5a2838e4407de3001da76d72",280 "name": "manual",281 "originalname": "components.pdf",282 "filename": "e506a9172af9259843342dc44c58f763",283 "path": "src/lib/seed/e506a9172af9259843342dc44c58f763",284 "size": 33600,285 "mimetype": "application/pdf",286 "__v": 2,287 "avgRating": 4,288 "rating": [289 {290 "_id": "5a283ba1e892b9001e44fd6e",291 "userid": "5a2838d7407de3001da76d00",292 "materialid": "5a2838e4407de3001da76d72",293 "rating": 4294 },295 {296 "_id": "5a2846614bd89f001ee98d36",297 "userid": "5a2838d7407de3001da76d1e",298 "materialid": "5a2838e4407de3001da76d72",299 "rating": 4300 }301 ]302 };303 it('returns a matching rating', async () => {304 const result = await post(PACT_HOST + '/api/product/material/5a2838e4407de3001da76d72/rating',305 {headers: headers, body: JSON.stringify({rating: 4})});306 expect(result).toEqual({...expected, status: 201})307 })308 })309 310 describe('Return a rating', () => {311 const headers = {312 'Accept': 'application/json',313 'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJmaXJzdE5hbWUiOiJGTnVzZXIyOSIsImVtYWlsIjoidXNlcjI5QHVzZXIuY29tIiwicm9sZSI6IlVTRVIifQ.w2_IERnUUMbnSeGHSjNv0CMIEC-YSA4UMksRXdv5g-8'314 };315 beforeAll(() => provider.addInteraction({316 uponReceiving: 'a request for getting a rating',317 withRequest: {318 method: 'GET',319 path: '/api/product/material/5a2838e4407de3001da76d72/rating',320 headers321 },322 willRespondWith: {323 status: 200,324 headers: { 'Content-Type': 'application/json; charset=utf-8' },325 body: Matchers.eachLike(326 {327 "_id": "5a283ba1e892b9001e44fd6e",328 "userid": "5a2838d7407de3001da76d00",329 "materialid": "5a2838e4407de3001da76d72",330 "rating": 4331 }332 )333 }334 })335 );336 337 it('returns a list of ratings', async () => {338 const result = await get(PACT_HOST + '/api/product/material/5a2838e4407de3001da76d72/rating', {headers});339 const expected =[340 {341 "_id": "5a283ba1e892b9001e44fd6e",342 "userid": "5a2838d7407de3001da76d00",343 "materialid": "5a2838e4407de3001da76d72",344 "rating": 4345 }];346 expected.status = 200; // fix for ugly mapping of response status347 expect(result).toEqual(expected)348 });349 it('successfully verifies', () => provider.verify())350 })351 */...

Full Screen

Full Screen

github.pact.test.js

Source:github.pact.test.js Github

copy

Full Screen

1const github = require('./github');2/* global provider PACT_BASE_URL */3jest.mock('./config', () => ({4 COGNITO_REDIRECT_URI: 'COGNITO_REDIRECT_URI',5 GITHUB_CLIENT_SECRET: 'GITHUB_CLIENT_SECRET',6 GITHUB_CLIENT_ID: 'GITHUB_CLIENT_ID',7 GITHUB_API_URL: 'GITHUB_API_URL',8 GITHUB_LOGIN_URL: 'GITHUB_LOGIN_URL',9}));10describe('GitHub Client Pact', () => {11 beforeAll(() => provider.setup());12 afterAll(() => provider.finalize());13 afterEach(() => provider.verify());14 describe('UserDetails endpoint', () => {15 const userDetailsRequest = {16 uponReceiving: 'a request for user details',17 withRequest: {18 method: 'GET',19 path: '/user',20 headers: {21 Accept: 'application/vnd.github.v3+json',22 Authorization: `token THIS_IS_MY_TOKEN`23 }24 }25 };26 describe('When the access token is good', () => {27 const EXPECTED_BODY = { name: 'Tim Jones' };28 beforeEach(() => {29 const interaction = {30 ...userDetailsRequest,31 state: 'Where the access token is good',32 willRespondWith: {33 status: 200,34 headers: {35 'Content-Type': 'application/json'36 },37 body: EXPECTED_BODY38 }39 };40 return provider.addInteraction(interaction);41 });42 // add expectations43 it('returns a sucessful body', done =>44 github(PACT_BASE_URL)45 .getUserDetails('THIS_IS_MY_TOKEN')46 .then(response => {47 expect(response).toEqual(EXPECTED_BODY);48 done();49 }));50 });51 describe('When the access token is bad', () => {52 const EXPECTED_ERROR = {53 error: 'This is an error',54 error_description: 'This is a description'55 };56 beforeEach(() => {57 const interaction = {58 ...userDetailsRequest,59 state: 'Where the access token is bad',60 willRespondWith: {61 status: 400,62 headers: {63 'Content-Type': 'application/json'64 },65 body: EXPECTED_ERROR66 }67 };68 return provider.addInteraction(interaction);69 });70 // add expectations71 it('rejects the promise', done => {72 github(PACT_BASE_URL)73 .getUserDetails('THIS_IS_MY_TOKEN')74 .catch(() => {75 done();76 });77 });78 });79 describe('When there is a server error response', () => {80 const EXPECTED_ERROR = {81 error: 'This is an error',82 error_description: 'This is a description'83 };84 beforeEach(() => {85 const interaction = {86 ...userDetailsRequest,87 state: 'Where there is a server error response',88 willRespondWith: {89 status: 200,90 headers: {91 'Content-Type': 'application/json'92 },93 body: EXPECTED_ERROR94 }95 };96 return provider.addInteraction(interaction);97 });98 // add expectations99 it('rejects the promise', done => {100 github(PACT_BASE_URL)101 .getUserDetails('THIS_IS_MY_TOKEN')102 .catch(() => {103 done();104 });105 });106 });107 });108 describe('UserEmails endpoint', () => {109 const userEmailsRequest = {110 uponReceiving: 'a request for user emails',111 withRequest: {112 method: 'GET',113 path: '/user/emails',114 headers: {115 Accept: 'application/vnd.github.v3+json',116 Authorization: `token THIS_IS_MY_TOKEN`117 }118 }119 };120 describe('When the access token is good', () => {121 const EXPECTED_BODY = [{ email: 'ben@example.com', primary: true }];122 beforeEach(() => {123 const interaction = {124 ...userEmailsRequest,125 state: 'Where the access token is good',126 willRespondWith: {127 status: 200,128 headers: {129 'Content-Type': 'application/json'130 },131 body: EXPECTED_BODY132 }133 };134 return provider.addInteraction(interaction);135 });136 // add expectations137 it('returns a sucessful body', done =>138 github(PACT_BASE_URL)139 .getUserEmails('THIS_IS_MY_TOKEN')140 .then(response => {141 expect(response).toEqual(EXPECTED_BODY);142 done();143 }));144 });145 describe('When the access token is bad', () => {146 const EXPECTED_ERROR = {147 error: 'This is an error',148 error_description: 'This is a description'149 };150 beforeEach(() => {151 const interaction = {152 ...userEmailsRequest,153 state: 'Where the access token is bad',154 willRespondWith: {155 status: 400,156 headers: {157 'Content-Type': 'application/json'158 },159 body: EXPECTED_ERROR160 }161 };162 return provider.addInteraction(interaction);163 });164 // add expectations165 it('rejects the promise', done => {166 github(PACT_BASE_URL)167 .getUserEmails('THIS_IS_MY_TOKEN')168 .catch(() => {169 done();170 });171 });172 });173 describe('When there is a server error response', () => {174 const EXPECTED_ERROR = {175 error: 'This is an error',176 error_description: 'This is a description'177 };178 beforeEach(() => {179 const interaction = {180 ...userEmailsRequest,181 state: 'Where there is a server error response',182 willRespondWith: {183 status: 200,184 headers: {185 'Content-Type': 'application/json'186 },187 body: EXPECTED_ERROR188 }189 };190 return provider.addInteraction(interaction);191 });192 // add expectations193 it('rejects the promise', done => {194 github(PACT_BASE_URL)195 .getUserEmails('THIS_IS_MY_TOKEN')196 .catch(() => {197 done();198 });199 });200 });201 });202 describe('Authorization endpoint' , () => {203 describe('always', () => {204 it('returns a redirect url', () => {205 expect(github(PACT_BASE_URL)206 .getAuthorizeUrl('client_id', 'scope', 'state', 'response_type')).to.equal(207 `${PACT_BASE_URL}/login/oauth/authorize?client_id=client_id&scope=scope&state=state&response_type=response_type`);208 });209 });210 });211 describe('Auth Token endpoint', () => {212 const accessTokenRequest = {213 uponReceiving: 'a request for an access token',214 withRequest: {215 method: 'POST',216 path: '/login/oauth/access_token',217 headers: {218 Accept: 'application/json',219 'Content-Type': 'application/json'220 },221 body: {222 // OAuth required fields223 grant_type: 'authorization_code',224 redirect_uri: 'COGNITO_REDIRECT_URI',225 client_id: 'GITHUB_CLIENT_ID',226 // GitHub Specific227 response_type: 'code',228 client_secret: 'GITHUB_CLIENT_SECRET',229 code: 'SOME_CODE'230 }231 }232 };233 describe('When the code is good', () => {234 const EXPECTED_BODY = {235 access_token: 'xxxx',236 refresh_token: 'yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy',237 expires_in: 21600238 };239 beforeEach(() => {240 const interaction = {241 ...accessTokenRequest,242 state: 'Where the code is good',243 willRespondWith: {244 status: 200,245 headers: {246 'Content-Type': 'application/json'247 },248 body: EXPECTED_BODY249 }250 };251 return provider.addInteraction(interaction);252 });253 // add expectations254 it('returns a sucessful body', done =>255 github(PACT_BASE_URL)256 .getToken('SOME_CODE')257 .then(response => {258 expect(response).toEqual(EXPECTED_BODY);259 done();260 }));261 });262 describe('When the code is bad', () => {263 const EXPECTED_ERROR = {264 error: 'This is an error',265 error_description: 'This is a description'266 };267 beforeEach(() => {268 const interaction = {269 ...accessTokenRequest,270 state: 'Where the code is bad',271 willRespondWith: {272 status: 400,273 headers: {274 'Content-Type': 'application/json'275 },276 body: EXPECTED_ERROR277 }278 };279 return provider.addInteraction(interaction);280 });281 // add expectations282 it('rejects the promise', done => {283 github(PACT_BASE_URL)284 .getToken('SOME_CODE')285 .catch(() => {286 done();287 });288 });289 });290 describe('When there is a server error response', () => {291 const EXPECTED_ERROR = {292 error: 'This is an error',293 error_description: 'This is a description'294 };295 beforeEach(() => {296 const interaction = {297 ...accessTokenRequest,298 state: 'Where there is a server error response',299 willRespondWith: {300 status: 200,301 headers: {302 'Content-Type': 'application/json'303 },304 body: EXPECTED_ERROR305 }306 };307 return provider.addInteraction(interaction);308 });309 // add expectations310 it('rejects the promise', done => {311 github(PACT_BASE_URL)312 .getToken('SOME_CODE')313 .catch(() => {314 done();315 });316 });317 });318 });...

Full Screen

Full Screen

converter.pact.spec.ts

Source:converter.pact.spec.ts Github

copy

Full Screen

1import { Container } from 'typescript-ioc';2import { BadRequestError } from 'typescript-rest/dist/server/model/errors';3import { ConverterService } from '../../src/services/converter.service';4import { resolve } from 'path';5import { Pact } from '@pact-foundation/pact';6const consumerName = 'markstur-calculator';7const providerName = 'markstur-converter';8const providerPort = +process.env.CONVERTER_PORT;9describe('Converter using Pact provider', () => {10 let service: ConverterService;11 let provider: Pact;12 beforeAll(async () => {13 service = Container.get(ConverterService);14 provider = new Pact({15 // cors: true,16 consumer: consumerName,17 provider: providerName,18 port: providerPort,19 log: resolve(process.cwd(), 'logs', 'pact.log'),20 dir: resolve(process.cwd(), 'pacts'),21 });22 await provider.setup();23 const baseState = 'base state';24 await Promise.all([25 provider.addInteraction({26 state: baseState,27 uponReceiving: 'a request to convert to-roman from 2021',28 withRequest: {29 method: 'GET',30 path: '/converter/to-roman',31 query: 'value=2021',32 },33 willRespondWith: {34 status: 200,35 body: 'MMXXI',36 },37 }),38 provider.addInteraction({39 state: baseState,40 uponReceiving: 'a request to convert to-roman from zero',41 withRequest: {42 method: 'GET',43 path: '/converter/to-roman',44 query: 'value=0',45 },46 willRespondWith: {47 status: 200,48 body: 'nulla',49 },50 }),51 provider.addInteraction({52 state: baseState,53 uponReceiving: 'a request to convert to-roman from 3999',54 withRequest: {55 method: 'GET',56 path: '/converter/to-roman',57 query: 'value=3999',58 },59 willRespondWith: {60 status: 200,61 body: 'MMMCMXCIX',62 },63 }),64 provider.addInteraction({65 state: baseState,66 uponReceiving: 'a request to convert to-roman from -1',67 withRequest: {68 method: 'GET',69 path: '/converter/to-roman',70 query: 'value=-1',71 },72 willRespondWith: {73 status: 400,74 },75 }),76 provider.addInteraction({77 state: baseState,78 uponReceiving: 'a request to convert to-roman from 12.34',79 withRequest: {80 method: 'GET',81 path: '/converter/to-roman',82 query: 'value=12.34',83 },84 willRespondWith: {85 status: 400,86 },87 }),88 provider.addInteraction({89 state: baseState,90 uponReceiving: 'a request to convert to-roman from 4000',91 withRequest: {92 method: 'GET',93 path: '/converter/to-roman',94 query: 'value=4000',95 },96 willRespondWith: {97 status: 400,98 },99 }),100 provider.addInteraction({101 state: baseState,102 uponReceiving: 'a request to convert to-number from XIIII',103 withRequest: {104 method: 'GET',105 path: '/converter/to-number',106 query: 'value=XIIII',107 },108 willRespondWith: {109 status: 400,110 },111 }),112 provider.addInteraction({113 state: baseState,114 uponReceiving: 'a request to convert to-number from "foo"',115 withRequest: {116 method: 'GET',117 path: '/converter/to-number',118 query: 'value=foo',119 },120 willRespondWith: {121 status: 400,122 },123 }),124 provider.addInteraction({125 state: baseState,126 uponReceiving: 'a request to convert to-number from ""',127 withRequest: {128 method: 'GET',129 path: '/converter/to-number',130 query: 'value=',131 },132 willRespondWith: {133 status: 400,134 },135 }),136 provider.addInteraction({137 state: baseState,138 uponReceiving: 'a request to convert to-number from "XZI"',139 withRequest: {140 method: 'GET',141 path: '/converter/to-number',142 query: 'value=XZI',143 },144 willRespondWith: {145 status: 400,146 },147 }),148 provider.addInteraction({149 state: baseState,150 uponReceiving: 'a request to convert to-number from "A"',151 withRequest: {152 method: 'GET',153 path: '/converter/to-number',154 query: 'value=A',155 },156 willRespondWith: {157 status: 400,158 },159 }),160 provider.addInteraction({161 state: baseState,162 uponReceiving: 'a request to convert to-number from "X I"',163 withRequest: {164 method: 'GET',165 path: '/converter/to-number',166 query: 'value=X I',167 },168 willRespondWith: {169 status: 400,170 },171 }),172 provider.addInteraction({173 state: baseState,174 uponReceiving: 'a request to convert to-number from "X.I"',175 withRequest: {176 method: 'GET',177 path: '/converter/to-number',178 query: 'value=X.I',179 },180 willRespondWith: {181 status: 400,182 },183 }),184 provider.addInteraction({185 state: baseState,186 uponReceiving: 'a request to convert to-number from MMXXI',187 withRequest: {188 method: 'GET',189 path: '/converter/to-number',190 query: 'value=MMXXI',191 },192 willRespondWith: {193 status: 200,194 body: '2021',195 },196 }),197 ]);198 }, 30000);199 test('canary test verifies test infrastructure', () => {200 expect(service).not.toBeUndefined();201 });202 afterAll(async () => {203 await provider.verify().finally(async () => {204 await provider.finalize();205 });206 });207 describe('given server requests', () => {208 describe('the proxy to the converter service provider should...', () => {209 it('handle positive integers between 0 and 3999 inclusive (0)', async () => {210 expect(await service.toRoman(0)).toEqual('nulla');211 });212 it('handle positive integers between 0 and 3999 inclusive (3999)', async () => {213 expect(await service.toRoman(3999)).toEqual('MMMCMXCIX');214 });215 it('return HTTP error code 400 - Bad Request if the number is negative', async () => {216 await expect(service.toRoman(-1)).rejects.toThrow(BadRequestError);217 });218 it('return HTTP error code 400 - Bad Request if the number is above 3999', async () => {219 await expect(service.toRoman(4000)).rejects.toThrow(BadRequestError);220 });221 it('return HTTP error code 400 - Bad Request if the number is a float (12.34)', async () => {222 await expect(service.toRoman(12.34)).rejects.toThrow(BadRequestError);223 });224 it('when converting from Roman Numerals if the value if not a valid Roman Numeral, such as XIIII, then return HTTP error code 400 - Bad Request', async () => {225 await expect(service.toNumber('XIIII')).rejects.toThrow(226 BadRequestError227 );228 });229 it('when converting to a Roman Numerals, if the value parameter is not a valid number then return HTTP error code 400 - Bad Request', async () => {230 await expect(service.toNumber('foo')).rejects.toThrow(BadRequestError);231 });232 it('empty string returns throw 400', async () => {233 await expect(service.toNumber('')).rejects.toThrow(BadRequestError);234 });235 it('"A" returns throw 400', async () => {236 await expect(service.toNumber('A')).rejects.toThrow(BadRequestError);237 });238 it('"XZI" returns throw 400', async () => {239 await expect(service.toNumber('XZI')).rejects.toThrow(BadRequestError);240 });241 it('"X I" returns throw 400', async () => {242 await expect(service.toNumber('X I')).rejects.toThrow(BadRequestError);243 });244 it('"X.I" returns throw 400', async () => {245 await expect(service.toNumber('X.I')).rejects.toThrow(BadRequestError);246 });247 });248 });249 describe('GET /api/converter/to-roman?value=2021', () => {250 it('should return MMXXI from the proxy provider', async () => {251 expect(await service.toRoman(2021)).toBe('MMXXI');252 });253 });254 describe('GET /api/converter/to-number?value=MMXXI', () => {255 it('should return 2021 from the proxy provider', async () => {256 expect(await service.toNumber('MMXXI')).toBe(2021);257 });258 });...

Full Screen

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