2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import expect from 'expect';
22 import $ from 'jquery';
23 import RestAPIUtil, {makeQueryParams} from 'src/nfvo-utils/RestAPIUtil';
25 const URL = 'http://bla.ble.blu/';
27 describe('RestAPIUtil Util class', () => {
30 $.ajax = (options) => options;
33 it('RestAPIUtil does exist', () => {
34 expect(RestAPIUtil).toExist();
37 it('RestAPIUtil makeQueryParams does exist', () => {
38 expect(makeQueryParams).toExist();
41 it('RestAPIUtil makeQueryParams params', () => {
42 const pageStart = 1, pageSize = 25;
43 const response = makeQueryParams({pagination: {pageStart, pageSize}});
44 expect(response.pageStart).toBe(pageStart);
45 expect(response.pageSize).toBe(pageSize);
48 it('normal basic fetch', () => {
49 const response = RestAPIUtil.fetch(URL);
50 expect(response).toExist();
53 it('no url', function () {
59 it('fetch with pagination', () => {
60 const pageStart = 1, pageSize = 25;
61 const response = RestAPIUtil.fetch(URL, {pagination: {pageStart, pageSize}});
62 expect(response.pagination).toExist();
63 expect(response.url).toInclude(`?pageStart=${pageStart}&pageSize=${pageSize}`);
66 it('fetch with sorting', () => {
67 const sortField = 'name', sortDir = 'ASCENDING';
68 const response = RestAPIUtil.fetch(URL, {sorting: {sortField, sortDir}});
69 expect(response.sorting).toExist();
70 expect(response.url).toInclude(`?sortField=${sortField}&sortDir=${sortDir}`);
73 it('fetch with filtering', () => {
76 criterionValue: 'service',
82 criterionValue: 'resource',
88 const response = RestAPIUtil.fetch(URL, {filtering: {filterCriteria: baseFilter, logicalRelation: 'OR'}});
89 expect(response.filtering).toExist();
90 expect(response.url).toInclude('?filter=');
93 it('fetch with qParams', () => {
94 const response = RestAPIUtil.fetch(URL, {qParams: {pageStart: 1, pageSize: 10}});
95 expect(response.qParams).toExist();
98 it('fetch with url on options', () => {
99 const response = RestAPIUtil.fetch(URL, {url:'12345', qParams: {pageStart: 1, pageSize: 10}});
100 expect(response.qParams).toExist();
103 it('fetch with url path param', () => {
104 let someData = 'data';
105 const response = RestAPIUtil.fetch(`${URL}{someData}/`, {params: {someData}});
106 expect(response.url).toInclude(`/${someData}/`);
109 it('fetch with url undefined path param', () => {
110 const response = RestAPIUtil.fetch(`${URL}{someData}/`, {params: {someData: undefined}});
111 expect(response.url).toInclude('/undefined/');
114 it('normal basic create', () => {
115 const response = RestAPIUtil.create(URL);
116 expect(response).toExist();
119 it('create with FormData', () => {
120 let formData = new FormData();
121 formData.append('username', 'Chris');
122 const response = RestAPIUtil.create(URL, formData);
123 expect(response).toExist();
126 it('create with FormData with md5', () => {
127 let formData = new FormData();
128 formData.append('username', 'Chris');
129 const response = RestAPIUtil.create(URL, formData, {md5: true});
130 expect(response).toExist();
133 it('create with file', () => {
134 let progressCallback = () => {};
135 const response = RestAPIUtil.create(URL, {}, {progressCallback, fileSize: 123});
136 expect(response).toExist();
139 it('normal basic save', () => {
140 const response = RestAPIUtil.save(URL);
141 expect(response).toExist();
144 it('normal basic delete', () => {
145 const response = RestAPIUtil.destroy(URL);
146 expect(response).toExist();