Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukashass committed Dec 2, 2021
1 parent 9923b21 commit fb2ca55
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 86 deletions.
20 changes: 5 additions & 15 deletions test/channels/.mockServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import path from "path";
import helmet from "helmet";
import cors from "cors";

import feathers from "@feathersjs/feathers";
import express, { Application } from "@feathersjs/express";
import { feathers } from "@feathersjs/feathers";
import express, { Application, json, urlencoded, rest } from "@feathersjs/express";
import socketio from "@feathersjs/socketio";
import { Service } from "feathers-memory";

Expand All @@ -20,9 +20,6 @@ interface MockServerOptions {

interface ExportMockServer {
app: Application
articles: Service
comments: Service
users: Service
}

const mockServer = (options: MockServerOptions): ExportMockServer => {
Expand All @@ -37,11 +34,11 @@ const mockServer = (options: MockServerOptions): ExportMockServer => {
contentSecurityPolicy: false
}));
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(json());
app.use(urlencoded({ extended: true }));

// Set up Plugins and providers
app.configure(express.rest());
app.configure(rest());
app.configure(socketio());

app.configure(services);
Expand All @@ -51,16 +48,9 @@ const mockServer = (options: MockServerOptions): ExportMockServer => {

app.hooks({});

const articles = app.service("articles");
const comments = app.service("comments");
const users = app.service("users");

app.configure(casl());
return {
app: app,
articles,
comments,
users
};
};

Expand Down
6 changes: 3 additions & 3 deletions test/channels/custom-actions/channels.custom-actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers, { Application } from "@feathersjs/feathers";
import { feathers, Application } from "@feathersjs/feathers";
import socketio from "@feathersjs/socketio-client";
import { Server } from "http";
import io from "socket.io-client";
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("channels.custom-actions.test.ts", function() {
app = mock.app;

const port = app.get("port");
server = app.listen(port);
server = await app.listen(port);
await new Promise((resolve) => {
server.on("listening", resolve);
});
Expand Down Expand Up @@ -194,4 +194,4 @@ describe("channels.custom-actions.test.ts", function() {
}
}
});
});
});
4 changes: 0 additions & 4 deletions test/channels/custom-actions/mockServices.custom-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export default function(app: Application): void {
authService.hooks({
after: {
all: [],
find: [],
get: [],
create: [
(context: HookContext): HookContext => {
const { user } = context.result;
Expand All @@ -73,8 +71,6 @@ export default function(app: Application): void {
return context;
}
],
update: [],
patch: [],
remove: []
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/channels/defaultSettings/channels.default.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers, { Application } from "@feathersjs/feathers";
import { feathers, Application } from "@feathersjs/feathers";
import socketio from "@feathersjs/socketio-client";
import { Server } from "http";
import io from "socket.io-client";
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("channels.default.test.ts", function() {
app = mock.app;

const port = app.get("port");
server = app.listen(port);
server = await app.listen(port);
await new Promise((resolve) => {
server.on("listening", resolve);
});
Expand Down Expand Up @@ -350,4 +350,4 @@ describe("channels.default.test.ts", function() {
}
}
});
});
});
4 changes: 0 additions & 4 deletions test/channels/defaultSettings/mockServices.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export default function(app: Application): void {
authService.hooks({
after: {
all: [],
find: [],
get: [],
create: [
(context: HookContext): HookContext => {
const { user } = context.result;
Expand All @@ -56,8 +54,6 @@ export default function(app: Application): void {
return context;
}
],
update: [],
patch: [],
remove: []
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/channels/receive/channels.receive.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers, { Application } from "@feathersjs/feathers";
import { feathers, Application } from "@feathersjs/feathers";
import socketio from "@feathersjs/socketio-client";
import { Server } from "http";
import io from "socket.io-client";
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("channels.receive.test.ts", function() {
app = mock.app;

const port = app.get("port");
server = app.listen(port);
server = await app.listen(port);
await new Promise((resolve) => {
server.on("listening", resolve);
});
Expand Down Expand Up @@ -192,4 +192,4 @@ describe("channels.receive.test.ts", function() {
}
}
});
});
});
4 changes: 0 additions & 4 deletions test/channels/receive/mockServices.receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export default function(app: Application): void {
authService.hooks({
after: {
all: [],
find: [],
get: [],
create: [
(context: HookContext): HookContext => {
const { user } = context.result;
Expand All @@ -67,8 +65,6 @@ export default function(app: Application): void {
return context;
}
],
update: [],
patch: [],
remove: []
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers, { Application } from "@feathersjs/feathers";
import { feathers, Application } from "@feathersjs/feathers";
import socketio from "@feathersjs/socketio-client";
import { Server } from "http";
import io from "socket.io-client";
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("channels.availableFields.test.ts", function() {
app = mock.app;

const port = app.get("port");
server = app.listen(port);
server = await app.listen(port);
await new Promise((resolve) => {
server.on("listening", resolve);
});
Expand Down Expand Up @@ -350,4 +350,4 @@ describe("channels.availableFields.test.ts", function() {
}
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export default function(app: Application): void {
authService.hooks({
after: {
all: [],
find: [],
get: [],
create: [
(context: HookContext): HookContext => {
const { user } = context.result;
Expand All @@ -63,8 +61,6 @@ export default function(app: Application): void {
return context;
}
],
update: [],
patch: [],
remove: []
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/create-multi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";
import _sortBy from "lodash/sortBy";

Expand Down Expand Up @@ -160,4 +160,4 @@ export default (
assert.deepStrictEqual(items, expected, "filtered properties");
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -184,4 +184,4 @@ export default (
assert.deepStrictEqual(itemInDb, item, "item in db is complete");
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/find.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers, { Paginated } from "@feathersjs/feathers";
import { feathers, Paginated } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";
import _sortBy from "lodash/sortBy";

Expand Down Expand Up @@ -491,4 +491,4 @@ export default (
});
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -183,4 +183,4 @@ export default (
);
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/patch-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -161,4 +161,4 @@ export default (
}
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/patch-multi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";
import _sortBy from "lodash/sortBy";
import _isEqual from "lodash/isEqual";
Expand Down Expand Up @@ -296,4 +296,4 @@ export default (
);
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/patch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -180,4 +180,4 @@ export default (
assert.deepStrictEqual(itemInDb, updatedItem, "item in db is complete");
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/remove-multi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";
import _sortBy from "lodash/sortBy";

Expand Down Expand Up @@ -253,4 +253,4 @@ export default (
);
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/remove.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -136,4 +136,4 @@ export default (
);
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/update-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -161,4 +161,4 @@ export default (
}
});
});
};
};
4 changes: 2 additions & 2 deletions test/hooks/authorize/adapters/makeTests/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import feathers from "@feathersjs/feathers";
import { feathers } from "@feathersjs/feathers";
import { createAliasResolver, defineAbility } from "@casl/ability";

const resolveAction = createAliasResolver({
Expand Down Expand Up @@ -211,4 +211,4 @@ export default (
assert.deepStrictEqual(itemInDb, updatedItem, "item in db is complete");
});
});
};
};
2 changes: 1 addition & 1 deletion test/hooks/authorize/authorize.general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
defineAbility
} from "@casl/ability";
import _cloneDeep from "lodash/cloneDeep";
import { markHookForSkip } from "feathers-utils/dist";
import { markHookForSkip } from "feathers-utils";
import { HOOKNAME as HOOKNAME_CHECKBASICPERMISSION } from "../../../lib/hooks/checkBasicPermission.hook";
import { HookContext } from "@feathersjs/feathers";

Expand Down
Loading

0 comments on commit fb2ca55

Please sign in to comment.