Skip to content

Commit

Permalink
Refactor test code after conversion from CoffeeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Amir Tocker committed Jan 15, 2019
1 parent ee88c34 commit d1e9930
Show file tree
Hide file tree
Showing 17 changed files with 1,379 additions and 1,944 deletions.
20 changes: 10 additions & 10 deletions lib-es5/preloaded_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var _createClass = function () { function defineProperties(target, props) { for

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var PRELOADED_CLOUDINARY_PATH, PreloadedFile, config, utils;
var PRELOADED_CLOUDINARY_PATH, config, utils;

utils = require("./utils");

config = require("./config");

PRELOADED_CLOUDINARY_PATH = /^([^\/]+)\/([^\/]+)\/v(\d+)\/([^#]+)#([^\/]+)$/;

PreloadedFile = function () {
var PreloadedFile = function () {
function PreloadedFile(file_info) {
_classCallCheck(this, PreloadedFile);

Expand Down Expand Up @@ -57,25 +57,25 @@ PreloadedFile = function () {
}, {
key: "identifier",
value: function identifier() {
return "v" + this.version + "/" + this.filename;
return `v${this.version}/${this.filename}`;
}
}, {
key: "toString",
value: function toString() {
return this.resource_type + "/" + this.type + "/v" + this.version + "/" + this.filename + "#" + this.signature;
return `${this.resource_type}/${this.type}/v${this.version}/${this.filename}#${this.signature}`;
}
}, {
key: "toJSON",
value: function toJSON() {
var key, ref, result, val;
result = {};
ref = this;
for (key in ref) {
val = ref[key];
var _this = this;

var result = {};
Object.getOwnPropertyNames(this).forEach(function (key) {
var val = _this[key];
if (typeof val !== 'function') {
result[key] = val;
}
}
});
return result;
}
}]);
Expand Down
20 changes: 9 additions & 11 deletions lib/preloaded_file.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var PRELOADED_CLOUDINARY_PATH, PreloadedFile, config, utils;
var PRELOADED_CLOUDINARY_PATH, config, utils;

utils = require("./utils");

config = require("./config");

PRELOADED_CLOUDINARY_PATH = /^([^\/]+)\/([^\/]+)\/v(\d+)\/([^#]+)#([^\/]+)$/;

PreloadedFile = class PreloadedFile {
class PreloadedFile {
constructor(file_info) {
var matches, public_id_and_format;
matches = file_info.match(PRELOADED_CLOUDINARY_PATH);
Expand Down Expand Up @@ -45,26 +45,24 @@ PreloadedFile = class PreloadedFile {
}

identifier() {
return "v" + this.version + "/" + this.filename;
return `v${this.version}/${this.filename}`;
}

toString() {
return this.resource_type + "/" + this.type + "/v" + this.version + "/" + this.filename + "#" + this.signature;
return `${this.resource_type}/${this.type}/v${this.version}/${this.filename}#${this.signature}`;
}

toJSON() {
var key, ref, result, val;
result = {};
ref = this;
for (key in ref) {
val = ref[key];
var result = {};
Object.getOwnPropertyNames(this).forEach((key) => {
let val = this[key];
if (typeof val !== 'function') {
result[key] = val;
}
}
});
return result;
}

};
}

module.exports = PreloadedFile;
94 changes: 39 additions & 55 deletions test/access_control_spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
var ClientRequest, cloudinary, escapeRegexp, expect, helper, http, isString, options, request, requestSpy, requestStub, sinon, utils, writeSpy, xhr;

require('dotenv').load({
silent: true
});

expect = require("expect.js");

cloudinary = require("../cloudinary");

utils = cloudinary.utils;

sinon = require('sinon');

ClientRequest = require('_http_client').ClientRequest;

http = require('http');

helper = require('./spechelper');

escapeRegexp = helper.escapeRegexp;
const expect = require("expect.js");
const cloudinary = require("../cloudinary");
const build_upload_params = cloudinary.utils.build_upload_params;
const helper = require('./spechelper');
const isString = require('lodash/isString');
var options = null;

isString = require('lodash/isString');

xhr = request = requestStub = requestSpy = writeSpy = options = void 0;
const ACL = {
access_type: 'anonymous',
start: new Date(Date.UTC(2019, 1, 22, 16, 20, 57)),
end: '2019-03-22 00:00 +0200'
};
const ACL_2 = {
access_type: 'anonymous',
start: '2019-02-22 16:20:57Z',
end: '2019-03-22 00:00 +0200'
};
const ACL_STRING = '{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}';

describe("Access Control", function() {
var acl, acl_2, acl_string, config;
before("Verify Configuration", function() {});
config = cloudinary.config(true);
if (!(config.api_key && config.api_secret)) {
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.");
}
before("Verify Configuration", function() {
let config = cloudinary.config(true);
if (!(config.api_key && config.api_secret)) {
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.");
}

});
this.timeout(helper.TIMEOUT_LONG);
after(function() {
config = cloudinary.config(true);
let config = cloudinary.config(true);
if (!(config.api_key && config.api_secret)) {
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.");
}
Expand All @@ -47,49 +45,35 @@ describe("Access Control", function() {
tags: [...helper.UPLOAD_TAGS, 'access_control_test']
};
});
acl = {
access_type: 'anonymous',
start: new Date(Date.UTC(2019, 1, 22, 16, 20, 57)),
end: '2019-03-22 00:00 +0200'
};
acl_2 = {
access_type: 'anonymous',
start: '2019-02-22 16:20:57Z',
end: '2019-03-22 00:00 +0200'
};
acl_string = '{"access_type":"anonymous","start":"2019-02-22 16:20:57 +0200","end":"2019-03-22 00:00 +0200"}';
return describe("build_upload_params", function() {
describe("build_upload_params", function() {
it("should accept a Hash value", function() {
var params;
params = cloudinary.utils.build_upload_params({
access_control: acl
let params = build_upload_params({
access_control: ACL
});
expect(params).to.have.key('access_control');
expect(isString(params.access_control)).to.be.ok();
return expect(params.access_control).to.match(/^\[.+\]$/);
expect(params.access_control).to.match(/^\[.+\]$/);
});
it("should accept an array of Hash values", function() {
var j, params;
params = cloudinary.utils.build_upload_params({
access_control: [acl, acl_2]
let params = build_upload_params({
access_control: [ACL, ACL_2]
});
expect(params).to.have.key('access_control');
expect(isString(params.access_control)).to.be.ok();
expect(params.access_control).to.match(/^\[.+\]$/);
j = JSON.parse(params.access_control);
let j = JSON.parse(params.access_control);
expect(j.length).to.be(2);
expect(j[0]["access_type"]).to.equal(acl.access_type);
expect(Date.parse(j[0]["start"])).to.equal(Date.parse(acl.start));
return expect(Date.parse(j[0]["end"])).to.equal(Date.parse(acl.end));
expect(j[0]["access_type"]).to.equal(ACL.access_type);
expect(Date.parse(j[0]["start"])).to.equal(Date.parse(ACL.start));
expect(Date.parse(j[0]["end"])).to.equal(Date.parse(ACL.end));
});
return it("should accept a JSON string", function() {
var params;
params = cloudinary.utils.build_upload_params({
access_control: acl_string
it("should accept a JSON string", function() {
let params = build_upload_params({
access_control: ACL_STRING
});
expect(params).to.have.key('access_control');
expect(isString(params.access_control)).to.be.ok();
return expect(params.access_control).to.equal(`[${acl_string}]`);
expect(params.access_control).to.equal(`[${ACL_STRING}]`);
});
});
});
Loading

0 comments on commit d1e9930

Please sign in to comment.