|
2 | 2 |
|
3 | 3 | const chai = require('chai');
|
4 | 4 | const expect = chai.expect;
|
| 5 | +const kongContext = require('../lib/kong/context'); |
| 6 | +const kongApi = require('../lib/kong/index'); |
| 7 | +const localKongHost = 'http://127.0.0.1:8001'; |
5 | 8 |
|
6 | 9 | describe('Kong API Object Specification', () => {
|
7 |
| - it('must be able to create an API', () => { |
8 |
| - expect(10).to.equal(10); |
| 10 | + it('must be able to create an API', async () => { |
| 11 | + const context = kongContext('', '', localKongHost); |
| 12 | + const kong = kongApi(context); |
| 13 | + const apiName = 'example-api-0'; |
| 14 | + const uriPath = '/test'; |
| 15 | + const upstreamUrl = 'https://github.com'; |
| 16 | + await kong.apis.createOrUpdateApi({ |
| 17 | + name: apiName, |
| 18 | + uris: [uriPath], |
| 19 | + upstream_url: upstreamUrl |
| 20 | + }); |
| 21 | + const result = await kong.apis.allApis(); |
| 22 | + expect(result).to.have.lengthOf(1); |
| 23 | + const firstResult = result[0]; |
| 24 | + expect(firstResult.name).to.equal(apiName); |
| 25 | + expect(firstResult.uris).to.have.lengthOf(1); |
| 26 | + expect(firstResult.uris[0]).to.equal(uriPath); |
| 27 | + expect(firstResult.upstream_url).to.equal(upstreamUrl); |
| 28 | + }); |
| 29 | + |
| 30 | + it('must be able to remove a created API', async () => { |
| 31 | + const context = kongContext('', '', localKongHost); |
| 32 | + const kong = kongApi(context); |
| 33 | + const apiName = 'example-api-1'; |
| 34 | + const uriPath = '/test'; |
| 35 | + const upstreamUrl = 'https://github.com'; |
| 36 | + await kong.apis.createOrUpdateApi({ |
| 37 | + name: apiName, |
| 38 | + uris: [uriPath], |
| 39 | + upstream_url: upstreamUrl |
| 40 | + }); |
| 41 | + const result = await kong.apis.allApis(); |
| 42 | + expect(result).to.have.lengthOf(1); |
| 43 | + await kong.apis.removeApi(apiName); |
| 44 | + const updatedResult = await kong.apis.allApis(); |
| 45 | + expect(updatedResult).to.be.empty; |
| 46 | + }); |
| 47 | + |
| 48 | + afterEach(async () => { |
| 49 | + // clean up all entities |
| 50 | + const context = kongContext('', '', localKongHost); |
| 51 | + const kong = kongApi(context); |
| 52 | + const apis = await kong.apis.allApis(); |
| 53 | + const apiNames = apis.map(eachApi => eachApi.name); |
| 54 | + apiNames.map(async name => await kong.apis.removeApi(name).catch(err => console.log(err.message))); |
9 | 55 | });
|
10 | 56 | });
|
0 commit comments