From ab785a4e71f56806cd3c7e019dda70c021b2f283 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Mon, 16 Dec 2024 11:26:46 +1100 Subject: [PATCH] style: fix lints (#1326) Signed-off-by: JP-Ellis --- src/common/request.spec.ts | 2 ++ src/dsl/graphql.spec.ts | 4 ++++ src/dsl/interaction.spec.ts | 1 + src/dsl/matchers.spec.ts | 17 +++++++++++++++++ .../proxy/stateHandler/setupStates.spec.ts | 2 ++ src/httpPact/ffi.spec.ts | 2 ++ src/messageConsumerPact.spec.ts | 3 +++ src/messageProviderPact.spec.ts | 7 +++++++ src/v3/matchers.spec.ts | 1 + src/v3/xml/xmlElement.spec.ts | 1 + 10 files changed, 40 insertions(+) diff --git a/src/common/request.spec.ts b/src/common/request.spec.ts index f120be74a..0cbf2858f 100644 --- a/src/common/request.spec.ts +++ b/src/common/request.spec.ts @@ -31,6 +31,7 @@ describe('Request', () => { expect(r).to.be.fulfilled, ]); }); + it('resolves when request succeeds with response body', () => { const body = 'body'; nock(url).get('/').reply(200, body); @@ -40,6 +41,7 @@ describe('Request', () => { expect(p).to.eventually.be.equal(body), ]); }); + it('rejects when request fails with error message', () => { const error = 'error'; nock(url).get('/').reply(400, error); diff --git a/src/dsl/graphql.spec.ts b/src/dsl/graphql.spec.ts index 8d3b4506f..df5fd5bd9 100644 --- a/src/dsl/graphql.spec.ts +++ b/src/dsl/graphql.spec.ts @@ -32,11 +32,13 @@ describe('GraphQLInteraction', () => { expect(json.request.body.operationName).to.eq('query'); }); }); + describe('when given an invalid operation', () => { it('fails with an error', () => { expect(interaction.withOperation.bind('aoeu')).to.throw(Error); }); }); + describe('when given a null operation', () => { it('creates a GrphQL Interaction', () => { interaction.uponReceiving('a request'); @@ -79,6 +81,7 @@ describe('GraphQLInteraction', () => { expect(json.request.body.variables).to.deep.eq({ foo: 'bar' }); }); }); + describe('when no variables are provided', () => { it('does not add the variables property to the payload', () => { interaction.uponReceiving('a request'); @@ -97,6 +100,7 @@ describe('GraphQLInteraction', () => { expect(json.request.body).to.not.have.property('variables'); }); }); + describe('when an empty variables object is presented', () => { it('adds the variables property to the payload', () => { interaction.uponReceiving('a request'); diff --git a/src/dsl/interaction.spec.ts b/src/dsl/interaction.spec.ts index 4448f8e68..6a45a5b0a 100644 --- a/src/dsl/interaction.spec.ts +++ b/src/dsl/interaction.spec.ts @@ -25,6 +25,7 @@ describe('Interaction', () => { const actual = new Interaction().uponReceiving('r').given('').state; expect(actual).to.eql({ description: 'r' }); }); + it('creates Interaction when nothing is passed', () => { const actual = new Interaction().uponReceiving('r').state; expect(actual).to.eql({ description: 'r' }); diff --git a/src/dsl/matchers.spec.ts b/src/dsl/matchers.spec.ts index 0f8b06b4e..160cd3b05 100644 --- a/src/dsl/matchers.spec.ts +++ b/src/dsl/matchers.spec.ts @@ -71,6 +71,7 @@ describe('Matcher', () => { like({ ...r }); like(Object.freeze(f)); }); + it('compiles when InterfaceToTemplate is used', () => { const template: InterfaceToTemplate = { someArray: ['one', 'two'], @@ -85,6 +86,7 @@ describe('Matcher', () => { const unused: AnyTemplate = like(template); }); }); + describe('with types', () => { it('compiles', () => { const template: ExampleType = { @@ -123,6 +125,7 @@ describe('Matcher', () => { ); }); }); + describe('and a failing example', () => { it('returns false', () => { expect(validateExample('not a date', ISO8601_DATE_FORMAT)).to.eql( @@ -131,6 +134,7 @@ describe('Matcher', () => { }); }); }); + describe('when given an invalid regex', () => { it('returns an error', () => { expect(() => { @@ -473,6 +477,7 @@ describe('Matcher', () => { expect(email()).to.be.an('object'); }); }); + describe('when given an invalid Email address', () => { it('returns an error', () => { expect(() => { @@ -489,6 +494,7 @@ describe('Matcher', () => { expect(uuid()).to.be.an('object'); }); }); + describe('when given an invalid UUID', () => { it('returns an error', () => { expect(() => { @@ -505,6 +511,7 @@ describe('Matcher', () => { expect(ipv4Address()).to.be.an('object'); }); }); + describe('when given an invalid ipv4Address', () => { it('returns an error', () => { expect(() => { @@ -524,6 +531,7 @@ describe('Matcher', () => { expect(ipv6Address()).to.be.an('object'); }); }); + describe('when given an invalid ipv6Address', () => { it('returns an error', () => { expect(() => { @@ -540,6 +548,7 @@ describe('Matcher', () => { expect(hexadecimal()).to.be.an('object'); }); }); + describe('when given an invalid hexadecimal', () => { it('returns an error', () => { expect(() => { @@ -555,10 +564,12 @@ describe('Matcher', () => { expect(boolean()).to.be.an('object'); expect(boolean().value).to.equal(true); }); + it('sets value=false', () => { expect(boolean(false)).to.be.an('object'); expect(boolean(false).value).to.equal(false); }); + it('sets value=true', () => { expect(boolean(true)).to.be.an('object'); expect(boolean(true).value).to.equal(true); @@ -606,6 +617,7 @@ describe('Matcher', () => { expect(rfc1123Timestamp()).to.be.an('object'); }); }); + describe('when given an invalid rfc1123Timestamp', () => { it('returns an error', () => { expect(() => { @@ -622,6 +634,7 @@ describe('Matcher', () => { expect(iso8601Time()).to.be.an('object'); }); }); + describe('when given an invalid iso8601Time', () => { it('returns an error', () => { expect(() => { @@ -638,6 +651,7 @@ describe('Matcher', () => { expect(iso8601Date()).to.be.an('object'); }); }); + describe('when given an invalid iso8601Date', () => { it('returns an error', () => { expect(() => { @@ -656,6 +670,7 @@ describe('Matcher', () => { expect(iso8601DateTime()).to.be.an('object'); }); }); + describe('when given an invalid iso8601DateTime', () => { it('returns an error', () => { expect(() => { @@ -683,6 +698,7 @@ describe('Matcher', () => { expect(iso8601DateTimeWithMillis()).to.be.an('object'); }); }); + describe('when given an invalid iso8601DateTimeWithMillis', () => { it('returns an error', () => { expect(() => { @@ -771,6 +787,7 @@ describe('Matcher', () => { expect(extractPayload(matcher)).to.eql(expected); }); }); + describe('when given a complex nested object with matchers', () => { it('removes all matching guff', () => { const o = somethingLike({ diff --git a/src/dsl/verifier/proxy/stateHandler/setupStates.spec.ts b/src/dsl/verifier/proxy/stateHandler/setupStates.spec.ts index b9bbec50b..da66b9a21 100644 --- a/src/dsl/verifier/proxy/stateHandler/setupStates.spec.ts +++ b/src/dsl/verifier/proxy/stateHandler/setupStates.spec.ts @@ -78,6 +78,7 @@ describe('#setupStates', () => { expect(executed).to.be.true; }); }); + describe('that do not return a value', () => { it('executes the handler and returns an empty Promise', async () => { await setupStates(state, opts); @@ -85,6 +86,7 @@ describe('#setupStates', () => { expect(executed).to.be.true; }); }); + describe('that specify a setup and teardown function', () => { it('executes the lifecycle specific handler and returns any provider state injected values', async () => { const res = await setupStates(state2, opts); diff --git a/src/httpPact/ffi.spec.ts b/src/httpPact/ffi.spec.ts index c38e2dbe9..174a4eddc 100644 --- a/src/httpPact/ffi.spec.ts +++ b/src/httpPact/ffi.spec.ts @@ -49,6 +49,7 @@ describe('Pact FFI', () => { expect(queryMock.calledWith('foo', 1, 'baz')); }); }); + describe('with single values', () => { it('calls the query ffi function for each value', () => { const queryMock = sinon.stub(); @@ -64,6 +65,7 @@ describe('Pact FFI', () => { expect(queryMock.calledWith('foo', 0, 'bar')); }); }); + describe('with array and single values', () => { it('calls the query ffi function for each value', () => { const queryMock = sinon.stub(); diff --git a/src/messageConsumerPact.spec.ts b/src/messageConsumerPact.spec.ts index 5da30d1d4..54d664218 100644 --- a/src/messageConsumerPact.spec.ts +++ b/src/messageConsumerPact.spec.ts @@ -44,6 +44,7 @@ describe('MessageConsumer', () => { }).to.throw(Error); }); }); + describe('when an empty content object has been given', () => { it('it should throw an error', () => { expect(() => { @@ -51,6 +52,7 @@ describe('MessageConsumer', () => { }).to.throw(Error); }); }); + describe('when an empty metadata object has been given', () => { it('it should throw an error', () => { expect(() => { @@ -96,6 +98,7 @@ describe('MessageConsumer', () => { return expect(hFn(testMessage)).to.eventually.be.fulfilled; }); }); + describe('when given a function that throws an Exception', () => { it('returns a Handler object that returns a rejected promise', () => { const failFn = () => Promise.reject(new Error('fail')); diff --git a/src/messageProviderPact.spec.ts b/src/messageProviderPact.spec.ts index bd2a74ac9..67b350442 100644 --- a/src/messageProviderPact.spec.ts +++ b/src/messageProviderPact.spec.ts @@ -58,6 +58,7 @@ describe('MesageProvider', () => { expect(provider).to.be.a('object'); expect(provider).to.respondTo('verify'); }); + it('creates a Provider with default log level if not specified', () => { provider = new MessageProviderPact({ messageProviders: {}, @@ -82,6 +83,7 @@ describe('MesageProvider', () => { setupVerificationHandler(req, res); }); }); + describe('when their is an invalid setup', () => { it('creates a valid express handler that rejects the message', (done) => { const setupVerificationHandler = ( @@ -112,6 +114,7 @@ describe('MesageProvider', () => { ); }); }); + describe('when given a handler that does not exist', () => { it('returns a failed promise', () => { const findHandler = (provider as any).findHandler.bind(provider); @@ -128,6 +131,7 @@ describe('MesageProvider', () => { 'yay', ]); }); + it('passes params to the handler', () => { const setupStates = (provider as any).setupStates.bind(provider); return expect( @@ -141,6 +145,7 @@ describe('MesageProvider', () => { ]); }); }); + describe('when given a state that does not have a handler', () => { it('returns an empty promise', () => { provider = new MessageProviderPact({ @@ -164,6 +169,7 @@ describe('MesageProvider', () => { }); }); }); + describe('#setupProxyServer', () => { describe('when the http server starts up', () => { it('returns a resolved promise', () => { @@ -173,6 +179,7 @@ describe('MesageProvider', () => { }); }); }); + describe('#setupProxyApplication', () => { it('returns a valid express app', () => { const setupProxyApplication = ( diff --git a/src/v3/matchers.spec.ts b/src/v3/matchers.spec.ts index 5b7c00dae..6e49ec2f3 100644 --- a/src/v3/matchers.spec.ts +++ b/src/v3/matchers.spec.ts @@ -643,6 +643,7 @@ describe('V3 Matchers', () => { expect(MatchersV3.reify(matcher)).to.eql(expected); }); }); + describe('when given a complex nested object with matchers', () => { it('removes all matching guff', () => { const o = MatchersV3.like({ diff --git a/src/v3/xml/xmlElement.spec.ts b/src/v3/xml/xmlElement.spec.ts index 0b9f9133d..96624a33c 100644 --- a/src/v3/xml/xmlElement.spec.ts +++ b/src/v3/xml/xmlElement.spec.ts @@ -85,6 +85,7 @@ describe('xml element', () => { expect(child.matcher?.['pact:matcher:type']).not.to.be.empty; } }); + it('sets content to an empty string if the Matcher has no value', () => { function noValueMatcher(): Matcher { return {