"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _util = require("util");
var $rdf = _interopRequireWildcard(require("rdflib"));
var _solidNamespace = _interopRequireDefault(require("solid-namespace"));
var _trustedApplications = require("./trustedApplications.utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
/* eslint-env jest */

global.TextEncoder = _util.TextEncoder;
global.TextDecoder = _util.TextDecoder;
var ns = (0, _solidNamespace["default"])($rdf);
describe('generateRandomString', function () {
  it('generates a random string five characters long', function () {
    expect((0, _trustedApplications.generateRandomString)().length).toBe(5);
  });
});
describe('getStatementsToDelete', function () {
  it('should return an empty array when there are no statements', function () {
    var mockStore = $rdf.graph();
    var mockOrigin = $rdf.sym('https://origin.example');
    var mockProfile = $rdf.sym('https://profile.example#me');
    expect((0, _trustedApplications.getStatementsToDelete)(mockOrigin, mockProfile, mockStore, ns)).toEqual([]);
  });
  it('should return all statements for the given origin', function () {
    var mockStore = $rdf.graph();
    var mockApplication = $rdf.sym('https://app.example');
    var mockOrigin = $rdf.sym('https://origin.example');
    var mockProfile = $rdf.sym('https://profile.example#me');
    mockStore.add(mockApplication, ns.acl('origin'), mockOrigin);
    mockStore.add(mockApplication, ns.acl('mode'), ns.acl('Read'));
    mockStore.add(mockProfile, ns.acl('trustedApp'), mockApplication);
    var statementsToDelete = (0, _trustedApplications.getStatementsToDelete)(mockOrigin, mockProfile, mockStore, ns);
    expect(statementsToDelete.length).toBe(3);
    expect(statementsToDelete).toMatchSnapshot();
  });
  it('should not return statements for a different origin', function () {
    var mockStore = $rdf.graph();
    var mockApplication = $rdf.sym('https://app.example');
    var mockOrigin = $rdf.sym('https://origin.example');
    var mockProfile = $rdf.sym('https://profile.example#me');
    mockStore.add(mockApplication, ns.acl('origin'), mockOrigin);
    mockStore.add(mockApplication, ns.acl('mode'), ns.acl('Read'));
    mockStore.add(mockProfile, ns.acl('trustedApp'), mockApplication);
    var statementsToDelete = (0, _trustedApplications.getStatementsToDelete)($rdf.lit('A different origin'),
    // @@ TODO Remove casting
    mockProfile, mockStore, ns);
    expect(statementsToDelete.length).toBe(0);
    expect(statementsToDelete).toEqual([]);
  });
});
describe('getStatementsToAdd', function () {
  it('should return all required statements to add the given permissions for a given origin', function () {
    var mockOrigin = $rdf.sym('https://origin.example');
    var mockProfile = $rdf.sym('https://profile.example#me');
    var modes = [ns.acl('Read').value, ns.acl('Write').value];
    var statementsToAdd = (0, _trustedApplications.getStatementsToAdd)(mockOrigin, 'mock_app_id', modes, mockProfile, ns);
    expect(statementsToAdd.length).toBe(4);
    expect(statementsToAdd).toMatchSnapshot();
  });
});
//# sourceMappingURL=trustedApplications.test.js.map