Remove Api.js and its tests
authorFrank Bessou <frank.bessou@logilab.fr>
Thu, 18 May 2017 10:33:38 +0200
changeset 213 0f0820dd5631
parent 212 7d6ca8b951d5
child 214 d6b4dfb58e1d
Remove Api.js and its tests
src/Api.js
test/index.js
--- a/src/Api.js	Thu May 18 10:06:12 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/* global fetch */
-
-import 'whatwg-fetch';
-
-import HypermediaClient from "./services/hypermedia.js";
-
-export class Api {
-
-    constructor(hypermediaClient) {
-        this.hypermediaClient = hypermediaClient;
-    }
-
-    jsonFetchCollection(url, options) {
-        // Filter out error response by returning and empty collection.
-        return this.hypermediaClient.jsonFetch(url, options)
-            .then(doc => {
-                if (doc.hasOwnProperty('errors')) {
-                    console.error(doc);
-                    return [];
-                }
-                return doc;
-            });
-    }
-
-    getRelatedSchema(etype, rtype, role = 'creation', targetType = null) {
-        let url = `/${etype}/relationships/${rtype}/schema?role=${role}`;
-        if (targetType !== null) {
-            url += `&target_type=${targetType}`;
-        }
-        return this.hypermediaClient.getSchema(url);
-    }
-
-    getEntities(etype) {
-        const route = `/${etype}/`;
-        const url = route;
-        return this.hypermediaClient.getResource(url).then( resource => {
-            resource.etype = etype;
-            resource.route = route;
-            return resource;
-        });
-    }
-
-    getEntity(etype, eid) {
-        const route = `/${etype}/${eid}`;
-        const url = route;
-        return this.hypermediaClient.getResource(url).then(resource => {
-            resource.etype = etype;
-            resource.eid = eid;
-            resource.route = route;
-            return resource;
-        });
-    }
-
-    relateEntity(etype, eid, rtype, attributes, targetType = null) {
-        let url = `/${etype}/${eid}/relationships/${rtype}`;
-        const options = {
-            method: 'POST',
-            headers: {
-                'Content-Type': 'application/json',
-            },
-        };
-        if (targetType !== null) {
-            url += `?target_type=${targetType}`;
-        }
-        if (attributes !== undefined) {
-            options.body = JSON.stringify(attributes);
-        }
-        return this.hypermediaClient.jsonFetch(url, options);
-    }
-
-    getTransitionsSchema(etype, eid) {
-        const url = `/${etype}/${eid}/transitions/schema?role=creation`;
-        return this.hypermediaClient.jsonSchemaFetch(url);
-    }
-
-    addTransition(etype, eid, attributes) {
-        const url = `/${etype}/${eid}/transitions`;
-        const options = {
-            method: 'POST',
-            headers: {
-                'Content-Type': 'application/json',
-            },
-            body: JSON.stringify(attributes),
-        };
-        return this.hypermediaClient.jsonFetch(url, options);
-    }
-}
-
-export default new Api(HypermediaClient);
--- a/test/index.js	Thu May 18 10:06:12 2017 +0200
+++ b/test/index.js	Thu May 18 10:33:38 2017 +0200
@@ -12,7 +12,6 @@
 import {merge} from 'lodash/object';
 
 import {buildFormData, appendPath} from '../src/utils';
-import {Api} from '../src/Api';
 import {ActionLink, ActionsDropDown, CollectionItemLink} from '../src/components/BaseViews';
 import {EntityMeta, EntityAttributes} from '../src/components/Entity';
 import {mapToSchema} from "../src/jsonaryutils";
@@ -545,36 +544,6 @@
     });
 });
 
-describe('Api', () => {
-
-    describe('getEntity', () => {
-        const hypermediaClient = new HttpHypermediaClient();
-        const api = new Api(hypermediaClient);
-
-        const etype = 'foo';
-        const eid = 123;
-        const route = `/${etype}/${eid}`;
-        const resource = {url: route, route: route, allowedActions: ['view'], data: mapToSchema('{}', '{}')};
-
-        beforeEach(() => {
-            sinon.stub(hypermediaClient, 'getResource').resolves(resource);
-        });
-
-        afterEach(() => {
-            hypermediaClient.getResource.restore();
-        });
-
-        it('should build an entity object containing getResource\'s result, etype and eid', done => {
-            api.getEntity(etype, eid).then( entity => {
-
-                const expectedEntity = merge({etype: etype, eid: eid}, resource);
-                expect(entity).to.deep.equal(expectedEntity);
-                done();
-            }).catch(done);
-        });
-    });
-});
-
 describe('ReactJsonSchemaAdapterFactory', () => {
     const adapterFactory = new ReactJsonSchemaAdapterFactory();