pmpact 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app/app.js CHANGED
@@ -39,11 +39,19 @@ const getPactVersion = (json) => {
39
39
  }
40
40
  }
41
41
 
42
+ function isValidVersion(version) {
43
+ return /^\d+\.\d+\.\d+$/.test(version);
44
+ }
45
+
42
46
  const getParser = (version) => {
43
- try {
44
- return require(`./parsers/${version}/pact-parser`);
45
- } catch(err) {
46
- throw new Error(`Could not find a parser for the pact specification version: ${version}`);
47
+ if(isValidVersion(version)){
48
+ try {
49
+ return require(`./parsers/${version}/pact-parser`);
50
+ } catch(err) {
51
+ throw new Error(`Could not find a parser for the pact specification version: ${version}`);
52
+ }
53
+ } else {
54
+ throw new Error(`Invalid pact-parser version supplied: ${version}`);
47
55
  }
48
56
  }
49
57
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmpact",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "A command line tool to convert Pact files to Postman collections.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,38 @@
1
+ {
2
+ "consumer": {
3
+ "name": "consumerName"
4
+ },
5
+ "provider": {
6
+ "name": "providerName"
7
+ },
8
+ "interactions": [
9
+ {
10
+ "description": "Interaction description",
11
+ "providerState": "provider state",
12
+ "request": {
13
+ "method": "GET",
14
+ "path": "/path1/path2",
15
+ "query": "p1=p1&p2=p2",
16
+ "headers": {
17
+ "Accept": "application/json"
18
+ }
19
+ },
20
+ "response": {
21
+ "status": 200,
22
+ "headers": {
23
+ "Access-Control-Allow-Methods": "*",
24
+ "Access-Control-Allow-Origin": "*",
25
+ "Content-Type": "application/json; charset=UTF-8"
26
+ },
27
+ "body": {
28
+ "data": 1
29
+ }
30
+ }
31
+ }
32
+ ],
33
+ "metadata": {
34
+ "pactSpecification": {
35
+ "version": "not-a-valid-version-pattern"
36
+ }
37
+ }
38
+ }
@@ -118,4 +118,12 @@ describe('pmpact > app', () => {
118
118
  }
119
119
  });
120
120
 
121
+ it('should throw an error when pact version is of incorrect format', async () => {
122
+ try {
123
+ await app.parse('./tests/fixtures/invalid-version-pact.json');
124
+ assert.ok(0, 'Should not resolve');
125
+ } catch(err) {
126
+ assert.ok(err.message.indexOf('Invalid pact-parser version supplied') !== -1);
127
+ }
128
+ });
121
129
  });