Bläddra i källkod

Merge pull request #529 from buglinjo/patch-1

Adding support of global bearer token variable.
Shalvah 2 år sedan
förälder
incheckning
6bc3487a74

+ 7 - 0
src/Writing/PostmanCollectionWriter.php

@@ -77,6 +77,13 @@ class PostmanCollectionWriter
             ],
             "bearer" => [
                 'type' => 'bearer',
+                'bearer' => [
+                    [
+                        'key'   => $this->config->get('auth.name'),
+                        'value' => $this->config->get('auth.use_value'),
+                        'type'  => 'string',
+                    ],
+                ],
             ],
             default => [
                 'type' => 'apikey',

+ 9 - 2
tests/Fixtures/collection.json

@@ -340,6 +340,13 @@
     }
   ],
   "auth": {
-    "type": "bearer"
+    "type": "bearer",
+    "bearer": [
+      {
+        "key": "key",
+        "value": null,
+        "type": "string"
+      }
+    ]
   }
-}
+}

+ 12 - 1
tests/Unit/PostmanCollectionWriterTest.php

@@ -224,7 +224,18 @@ class PostmanCollectionWriterTest extends TestCase
         $config['auth']['in'] = 'bearer';
         $collection = $this->generate($config, [$endpoints]);
 
-        $this->assertEquals(['type' => 'bearer'], $collection['auth']);
+        $expected = [
+            'type'   => 'bearer',
+            'bearer' => [
+                [
+                    'key'   => null,
+                    'value' => null,
+                    'type'  => 'string',
+                ],
+            ],
+        ];
+
+        $this->assertEquals($expected, $collection['auth']);
         $this->assertArrayNotHasKey('auth', $collection['item'][0]['item'][0]['request']);
         $this->assertEquals(['type' => 'noauth'], $collection['item'][0]['item'][1]['request']['auth']);