Skip to content

Commit

Permalink
fixed direc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tompahoward committed Nov 23, 2020
1 parent d8eea43 commit e795f3c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/test/clients/waychaser-direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import logging from "selenium-webdriver/lib/logging";
import { BROWSER_PORT, BROWSER_HOST } from "../config";
import { utils } from "istanbul";
import { waychaser } from "../../waychaser";
import { response } from "express";

class WaychaserDirect {
async load(url) {
try {
logger.test("loading %s", url);
const resource = await waychaser.load(url);
logger.test("loaded %s: $s", url, resource);
return { success: true, resource };
} catch (error) {
logger.error("error loading %s", error);
return { success: false, error };
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const logger = {
browser: debug("browser"),
remote: debug("remote"),
waychaser: debug("waychaser"),
test: debug("test"),
};

logger.debug.log = console.log.bind(console);
Expand All @@ -14,8 +15,9 @@ logger.error.log = console.log.bind(console);
logger.browser.log = console.log.bind(console);
logger.remote.log = console.log.bind(console);
logger.waychaser.log = console.log.bind(console);
logger.test.log = console.log.bind(console);

debug.enable("debug,info,error,browser,remote,waychaser");
debug.enable("debug,info,error,browser,remote,waychaser,test");

export default logger;

Expand Down
30 changes: 16 additions & 14 deletions src/waychaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,39 @@ polyfill();
* @param options
*/
function loadResource(url, options) {
window.testLogger(`loading ${url}`);
logger.waychaser(`loading ${url}`);
return fetch(url, options).then((response) => {
if (!response.ok) {
window.testLogger(`Bad response from server ${JSON.stringify(response)}`);
logger.waychaser(`Bad response from server ${JSON.stringify(response)}`);
throw new Error("Bad response from server", response);
}
window.testLogger(`Good response from server ${JSON.stringify(response)}`);
// in ie url is not being populated 🤷‍♂️
response.url = url;
logger.waychaser(`Good response from server ${JSON.stringify(response)}`);
if (response.url === undefined || response.url === "") {
// in ie url is not being populated 🤷‍♂️
response.url = url;
}
return new waychaser.ApiResourceObject(response);
});
}

class Operation {
constructor(callingContext) {
window.testLogger(
logger.waychaser(
`Operation callingContext ${JSON.stringify(this.callingContext)}`
);
this.callingContext = callingContext;
}

async invoke(context, options) {
window.testLogger(`invoke`);
logger.waychaser(`invoke`);
// logger.waychaser(this, context, options);
const contextUrl = this.callingContext.url;
window.testLogger(`constext ${JSON.stringify(this.callingContext)}`);
window.testLogger(`constext ${this.callingContext.url}`);
window.testLogger(`constext ${contextUrl}`);
logger.waychaser(`constext ${JSON.stringify(this.callingContext)}`);
logger.waychaser(`constext ${this.callingContext.url}`);
logger.waychaser(`constext ${contextUrl}`);
const invokeUrl = new URL(this.uri, contextUrl);
// logger.waychaser({ invokeUrl });
window.testLogger(`invoking ${invokeUrl}`);
logger.waychaser(`invoking ${invokeUrl}`);
return loadResource(invokeUrl, options);
}
}
Expand All @@ -54,7 +56,7 @@ Loki.Collection.prototype.invokeByRel = async function (
options
) {
const operation = this.findOneByRel(relationship);
window.testLogger(JSON.stringify(operation, undefined, 2));
logger.waychaser(JSON.stringify(operation, undefined, 2));
return operation.invoke(context, options);
};

Expand Down Expand Up @@ -89,11 +91,11 @@ const waychaser = {
this.operations.insert(
links.refs.map((reference) => {
logger.waychaser({ reference });
window.testLogger(JSON.stringify(response));
logger.waychaser(JSON.stringify(response));

logger.waychaser("creating operation", response, reference);
const operation = new Operation(response);
window.testLogger(JSON.stringify({ operation }));
logger.waychaser(JSON.stringify({ operation }));
const operationX = Object.assign(operation, reference);
logger.waychaser(JSON.stringify({ operation: operationX }));
return operation;
Expand Down

0 comments on commit e795f3c

Please sign in to comment.