|
| 1 | +/** |
| 2 | + * Copyright 2016-2019 IBM Corp. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { WatsonMiddleware } from '../lib/index'; |
| 18 | +import nock = require('nock'); |
| 19 | + |
| 20 | +//Watson Assistant params |
| 21 | +const service = { |
| 22 | + username: 'batman', |
| 23 | + password: 'bruce-wayne', |
| 24 | + url: 'http://ibm.com:80', |
| 25 | + version: '2018-07-10', |
| 26 | +}; |
| 27 | + |
| 28 | +const workspaceId = 'zyxwv-54321'; |
| 29 | + |
| 30 | +const customerId = 'XXXXXX'; |
| 31 | + |
| 32 | +const middleware = new WatsonMiddleware({ |
| 33 | + ...service, |
| 34 | + workspace_id: workspaceId, |
| 35 | +}); |
| 36 | + |
| 37 | +beforeEach(function() { |
| 38 | + nock.disableNetConnect(); |
| 39 | +}); |
| 40 | + |
| 41 | +afterEach(function() { |
| 42 | + nock.cleanAll(); |
| 43 | +}); |
| 44 | + |
| 45 | +test('makes delete request', async () => { |
| 46 | + nock(service.url) |
| 47 | + .delete(`/v1/user_data?version=2018-07-10&customer_id=${customerId}`) |
| 48 | + .reply(202, ''); |
| 49 | + |
| 50 | + await middleware.deleteUserData(customerId); |
| 51 | +}); |
| 52 | + |
| 53 | +test('throws error on unexpected response code', async () => { |
| 54 | + nock(service.url) |
| 55 | + .delete(`/v1/user_data?version=2018-07-10&customer_id=${customerId}`) |
| 56 | + .reply(404, ''); |
| 57 | + |
| 58 | + return await expect(middleware.deleteUserData(customerId)).rejects.toThrow( |
| 59 | + 'Failed to delete user data, response code: 404, message: null', |
| 60 | + ); |
| 61 | +}); |
0 commit comments