Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Commit

Permalink
fixes based on feedback around errors running gulp serve
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-rodgers committed Dec 27, 2016
1 parent 3f08e4a commit 6c850ff
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 42 deletions.
24 changes: 12 additions & 12 deletions src/utils/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,35 @@ export class ProcessHttpClientResponseException extends Exception {

constructor(private response: Response) {
super("ProcessHttpClientResponseException", `Error making HttpClient request in queryable: [${response.status}] ${response.statusText}`);
this.Log();
super.Log();
}

protected getLogEntry(): Promise<LogEntry> {
return Promise.resolve(<LogEntry>{ data: this.response, level: LogLevel.Error, message: this.message });
return this.response.json().then(json => <LogEntry>{ data: json, level: LogLevel.Error, message: this.message });
}
}

export class NoCacheAvailableException extends Exception {

constructor(msg = "Cannot create a caching configuration provider since cache is not available.") {
super("NoCacheAvailableException", msg);
this.Log();
super.Log();
}
}

export class APIUrlException extends Exception {

constructor(msg = "Unable to determine API url.") {
super("APIUrlException", msg);
this.Log();
super.Log();
}
}

export class AuthUrlException extends Exception {

constructor(protected data: any, msg = "Auth URL Endpoint could not be determined from data. Data logged.") {
super("APIUrlException", msg);
this.Log();
super.Log();
}

protected getLogEntry(): Promise<LogEntry> {
Expand All @@ -85,7 +85,7 @@ export class SPRequestExecutorUndefinedException extends Exception {
"Load the SP.RequestExecutor.js library (/_layouts/15/SP.RequestExecutor.js) before loading the PnP JS Core library.",
].join(" ");
super("SPRequestExecutorUndefinedException", msg);
this.Log();
super.Log();
}
}

Expand All @@ -101,15 +101,15 @@ export class NotSupportedInBatchException extends Exception {

constructor(operation = "This operation") {
super("NotSupportedInBatchException", `${operation} is not supported as part of a batch.`);
this.Log();
super.Log();
}
}

export class ODataIdException extends Exception {

constructor(protected data: any, msg = "Could not extract odata id in object, you may be using nometadata. Object data logged to logger.") {
super("ODataIdException", msg);
this.Log();
super.Log();
}

protected getLogEntry(): Promise<LogEntry> {
Expand All @@ -122,30 +122,30 @@ export class BatchParseException extends Exception {

constructor(msg: string) {
super("BatchParseException", msg);
this.Log();
super.Log();
}
}

export class AlreadyInBatchException extends Exception {

constructor(msg = "This query is already part of a batch.") {
super("AlreadyInBatchException", msg);
this.Log();
super.Log();
}
}

export class FunctionExpectedException extends Exception {

constructor(msg = "This query is already part of a batch.") {
super("FunctionExpectedException", msg);
this.Log();
super.Log();
}
}

export class UrlException extends Exception {

constructor(msg: string) {
super("UrlException", msg);
this.Log();
super.Log();
}
}
2 changes: 1 addition & 1 deletion tests/configuration/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import * as Collections from "../../src/collections/collections";
import * as Configuration from "../../src/configuration/configuration";
import {default as MockConfigurationProvider} from "../mocks/mockConfigurationProvider";
import {default as MockConfigurationProvider} from "../mocks/mockconfigurationprovider";

describe("Configuration", () => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect } from "chai";
import { default as CachingConfigurationProvider } from "../../../src/configuration/providers/cachingConfigurationProvider";
import * as Collections from "../../../src/collections/collections";
import * as Configuration from "../../../src/configuration/configuration";
import {default as MockConfigurationProvider} from "../../mocks/mockConfigurationProvider";
import MockStorage from "../../mocks/MockStorage";
import {default as MockConfigurationProvider} from "../../mocks/mockconfigurationprovider";
import MockStorage from "../../mocks/mockstorage";
import * as storage from "../../../src/utils/storage";

describe("Configuration", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { default as SPListConfigurationProvider } from "../../../src/configuration/providers/spListConfigurationProvider";
import MockStorage from "../../mocks/MockStorage";
import MockStorage from "../../mocks/mockstorage";
import * as Collections from "../../../src/collections/collections";
import { Web } from "../../../src/sharepoint/webs";

Expand Down
10 changes: 7 additions & 3 deletions tests/mocks/MockLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ export default class MockLocation implements Location {
public protocol: string;
public search: string;

private _url: string;

public assign(url: string): void {
return;
this._url = url;
}

public reload(forcedReload?: boolean): void {
return;
if (forcedReload) {
this._url = "";
}
}

public replace(url: string): void {
return;
this._url = url;
}
public toString(): string {
return "MockLocation.toString";
Expand Down
5 changes: 4 additions & 1 deletion tests/mocks/MockStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import * as Collections from "../../src/collections/collections";
export default class MockStorage implements Storage {
constructor() {
this._store = new Collections.Dictionary<string>();
this._length = 0;
}

private _store: Collections.Dictionary<any>;

private _length: number;

public get length(): number {
return this._store.count();
}

public set length(i: number) {
return;
this._length = i;
}

public clear(): void {
Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/contenttypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { ContentTypes, ContentType } from "../../src/sharepoint/ContentTypes";
import { ContentTypes, ContentType } from "../../src/sharepoint/contenttypes";
import pnp from "../../src/pnp";
import { testSettings } from "../test-config.test";
import { toMatchEndRegex } from "../testutils";
Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/queryable.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { QueryableInstance, QueryableCollection } from "../../src/sharepoint/Queryable";
import { QueryableInstance, QueryableCollection } from "../../src/sharepoint/queryable";

describe("QueryableInstance", () => {

Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/quicklaunch.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import { expect } from "chai";
import { QuickLaunch } from "../../src/sharepoint/quickLaunch";
import { QuickLaunch } from "../../src/sharepoint/quicklaunch";
import { toMatchEndRegex } from "../testutils";

describe("QuickLaunch", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/sitegroups.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { SiteGroup, SiteGroups } from "../../src/sharepoint/siteGroups";
import { SiteGroup, SiteGroups } from "../../src/sharepoint/sitegroups";
import { toMatchEndRegex } from "../testutils";

describe("SiteGroups", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/siteusers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { SiteUser, SiteUsers } from "../../src/sharepoint/siteUsers";
import { SiteUser, SiteUsers } from "../../src/sharepoint/siteusers";
import { toMatchEndRegex } from "../testutils";

describe("SiteUsers", () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/sharepoint/topnavigationbar.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { TopNavigationBar } from "../../src/sharepoint/topNavigationBar";
import { TopNavigationBar } from "../../src/sharepoint/topnavigationbar";
import { toMatchEndRegex } from "../testutils";

describe("TopNavigationBar", () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/test-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare var global: any;
import * as chai from "chai";
import * as mocha from "mocha";
import "mocha";
import pnp from "../src/pnp";
import { Util } from "../src/utils/util";
import { Web } from "../src/sharepoint/webs";
Expand Down Expand Up @@ -68,10 +68,10 @@ after(() => {
// this can be used to clean up lots of test sub webs :)
export function cleanUpAllSubsites() {
pnp.sp.site.rootWeb.webs.select("Title").get().then((w) => {
w.forEach(element => {
w.forEach((element: any) => {
let web = new Web(element["odata.id"], "");
web.webs.select("Title").get().then((sw: any[]) => {
return Promise.all(sw.map((value, index, arr) => {
return Promise.all(sw.map((value) => {
let web2 = new Web(value["odata.id"], "");
return web2.delete();
}));
Expand Down
12 changes: 6 additions & 6 deletions tests/utils/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ describe("Logging", () => {
});

it("Should return an accurate count of subscribers", () => {
logger.subscribe(new Logging.FunctionListener((e) => { return; }));
logger.subscribe(new Logging.FunctionListener((e) => { return; }));
logger.subscribe(new Logging.FunctionListener((e) => { return; }));
logger.subscribe(new Logging.FunctionListener(() => { return; }));
logger.subscribe(new Logging.FunctionListener(() => { return; }));
logger.subscribe(new Logging.FunctionListener(() => { return; }));
expect(logger.count).to.eq(3);
});

it("Should allow multiple subscribes to be added in one call", () => {
logger.subscribe(
new Logging.FunctionListener((e) => { return; }),
new Logging.FunctionListener((e) => { return; }),
new Logging.FunctionListener((e) => { return; })
new Logging.FunctionListener(() => { return; }),
new Logging.FunctionListener(() => { return; }),
new Logging.FunctionListener(() => { return; })
);
expect(logger.count).to.eq(3);
});
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/storage.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import * as Storage from "../../src/utils/Storage";
import MockStorage from "../mocks/MockStorage";
import * as Storage from "../../src/utils/storage";
import MockStorage from "../mocks/mockstorage";

describe("Storage", () => {

Expand Down Expand Up @@ -28,7 +28,7 @@ describe("Storage", () => {
});

it("Use getOrPut to add a value using a getter function and return it", () => {
wrapper.getOrPut("test", function () { return new Promise((r, n) => "value"); }).then(function () {
wrapper.getOrPut("test", function () { return new Promise(() => "value"); }).then(function () {
let ret = wrapper.get("test");
expect(ret).to.eq("value");
});
Expand Down
20 changes: 16 additions & 4 deletions tests/utils/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@ describe("Util", () => {

describe("getCtxCallback", () => {
it("Should create contextual callback", () => {
let func = function (a) { this.num = this.num + a; };
let ctx = { num: 1 };
let callback = Util.getCtxCallback(ctx, func, 7);

class test {
constructor() {
this.num = 1;
}
public num: number;
public func(a: number) {
this.num += a;
}
}

let t = new test();

let callback = Util.getCtxCallback(t, t.func, 7);
expect(callback).to.exist;
expect(callback).to.be.a("function");
// this call will update ctx var inside the callback
expect(t.num).to.eq(1);
callback();
expect(ctx.num).to.eq(8);
expect(t.num).to.eq(8);
});
});

Expand Down

0 comments on commit 6c850ff

Please sign in to comment.