Skip to content

Commit

Permalink
test(SCIMMY.Resources.{User,Group}): check context is passed through …
Browse files Browse the repository at this point in the history
…to handlers
  • Loading branch information
sleelin committed Apr 16, 2024
1 parent c8668f8 commit 0fa9bf7
Show file tree
Hide file tree
Showing 13 changed files with 605 additions and 269 deletions.
690 changes: 497 additions & 193 deletions test/hooks/resources.js

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions test/hooks/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ export const createSchemaClass = ({name = "Test", id = "urn:ietf:params:scim:sch
}
);

export default {
construct: (TargetSchema, fixtures) => (() => {
export default class ResourcesHooks {
#target;
#fixtures;

constructor(TargetResource, fixtures) {
this.#target = TargetResource;
this.#fixtures = fixtures;
}

construct = () => (() => {
const TargetSchema = this.#target;
const fixtures = this.#fixtures;

it("should require 'resource' parameter to be an object at instantiation", () => {
assert.throws(() => new TargetSchema(),
{name: "TypeError", message: "Expected 'data' parameter to be an object in SchemaDefinition instance"},
Expand Down Expand Up @@ -207,8 +218,12 @@ export default {
{name: "TypeError", message: `Cannot delete property 'meta' of #<${instance.constructor.name}>`},
"Schema was not sealed after instantiation");
});
}),
definition: (TargetSchema, fixtures) => (() => {
});

definition = () => (() => {
const TargetSchema = this.#target;
const fixtures = this.#fixtures;

it("should be defined", () => {
assert.ok("definition" in TargetSchema,
"Static member 'definition' not defined");
Expand All @@ -225,5 +240,5 @@ export default {
assert.deepStrictEqual(JSON.parse(JSON.stringify(TargetSchema.definition.describe("/Schemas"))), definition,
"Definition did not match sample schema defined in RFC7643");
});
})
});
};
26 changes: 14 additions & 12 deletions test/lib/resources/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./group.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Resources.Group", () => {
describe(".endpoint", ResourcesHooks.endpoint(Group));
describe(".schema", ResourcesHooks.schema(Group));
describe(".basepath()", ResourcesHooks.basepath(Group));
describe(".extend()", ResourcesHooks.extend(Group, false));
describe(".ingress()", ResourcesHooks.ingress(Group, fixtures));
describe(".egress()", ResourcesHooks.egress(Group, fixtures));
describe(".degress()", ResourcesHooks.degress(Group, fixtures));
describe("@constructor", ResourcesHooks.construct(Group));
describe("#read()", ResourcesHooks.read(Group, fixtures));
describe("#write()", ResourcesHooks.write(Group, fixtures));
describe("#patch()", ResourcesHooks.patch(Group, fixtures));
describe("#dispose()", ResourcesHooks.dispose(Group, fixtures));
const hooks = new ResourcesHooks(Group, fixtures);

describe(".schema", hooks.schema(true));
describe(".endpoint", hooks.endpoint());
describe(".basepath()", hooks.basepath());
describe(".extend()", hooks.extend(true));
describe(".ingress()", hooks.ingress(true));
describe(".egress()", hooks.egress(true));
describe(".degress()", hooks.degress(true));
describe("@constructor", hooks.construct(true));
describe("#read()", hooks.read(true, true));
describe("#write()", hooks.write(true));
describe("#patch()", hooks.patch(true));
describe("#dispose()", hooks.dispose(true));
});
25 changes: 13 additions & 12 deletions test/lib/resources/resourcetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./resourcetype.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Resources.ResourceType", () => {
const hooks = new ResourcesHooks(ResourceType, fixtures);
const sandbox = sinon.createSandbox();

after(() => sandbox.restore());
Expand All @@ -22,16 +23,16 @@ describe("SCIMMY.Resources.ResourceType", () => {
.withArgs(User.schema.definition.name).returns(User);
});

describe(".endpoint", ResourcesHooks.endpoint(ResourceType));
describe(".schema", ResourcesHooks.schema(ResourceType, false));
describe(".basepath()", ResourcesHooks.basepath(ResourceType));
describe(".extend()", ResourcesHooks.extend(ResourceType, true));
describe(".ingress()", ResourcesHooks.ingress(ResourceType, false));
describe(".egress()", ResourcesHooks.egress(ResourceType, false));
describe(".degress()", ResourcesHooks.degress(ResourceType, false));
describe("@constructor", ResourcesHooks.construct(ResourceType, false));
describe("#read()", ResourcesHooks.read(ResourceType, fixtures));
describe("#write()", ResourcesHooks.write(ResourceType, false));
describe("#patch()", ResourcesHooks.patch(ResourceType, false));
describe("#dispose()", ResourcesHooks.dispose(ResourceType, false));
describe(".schema", hooks.schema(false));
describe(".endpoint", hooks.endpoint());
describe(".basepath()", hooks.basepath());
describe(".extend()", hooks.extend(false));
describe(".ingress()", hooks.ingress(false));
describe(".egress()", hooks.egress(false));
describe(".degress()", hooks.degress(false));
describe("@constructor", hooks.construct(false));
describe("#read()", hooks.read(true));
describe("#write()", hooks.write(false));
describe("#patch()", hooks.patch(false));
describe("#dispose()", hooks.dispose(false));
});
25 changes: 13 additions & 12 deletions test/lib/resources/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./schema.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Resources.Schema", () => {
const hooks = new ResourcesHooks(Schema, fixtures);
const sandbox = sinon.createSandbox();

after(() => sandbox.restore());
Expand All @@ -22,16 +23,16 @@ describe("SCIMMY.Resources.Schema", () => {
.withArgs(User.definition.id).returns(User.definition);
});

describe(".endpoint", ResourcesHooks.endpoint(Schema));
describe(".schema", ResourcesHooks.schema(Schema, false));
describe(".basepath()", ResourcesHooks.basepath(Schema));
describe(".extend()", ResourcesHooks.extend(Schema, true));
describe(".ingress()", ResourcesHooks.ingress(Schema, false));
describe(".egress()", ResourcesHooks.egress(Schema, false));
describe(".degress()", ResourcesHooks.degress(Schema, false));
describe("@constructor", ResourcesHooks.construct(Schema, false));
describe("#read()", ResourcesHooks.read(Schema, fixtures));
describe("#write()", ResourcesHooks.write(Schema, false));
describe("#patch()", ResourcesHooks.patch(Schema, false));
describe("#dispose()", ResourcesHooks.dispose(Schema, false));
describe(".schema", hooks.schema(false));
describe(".endpoint", hooks.endpoint());
describe(".basepath()", hooks.basepath());
describe(".extend()", hooks.extend(false));
describe(".ingress()", hooks.ingress(false));
describe(".egress()", hooks.egress(false));
describe(".degress()", hooks.degress(false));
describe("@constructor", hooks.construct(false));
describe("#read()", hooks.read(true));
describe("#write()", hooks.write(false));
describe("#patch()", hooks.patch(false));
describe("#dispose()", hooks.dispose(false));
});
25 changes: 13 additions & 12 deletions test/lib/resources/spconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./spconfig.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Resources.ServiceProviderConfig", () => {
const hooks = new ResourcesHooks(ServiceProviderConfig, fixtures);
const sandbox = sinon.createSandbox();

after(() => sandbox.restore());
Expand All @@ -20,16 +21,16 @@ describe("SCIMMY.Resources.ServiceProviderConfig", () => {
patch: {supported: false}, changePassword: {supported: false}, etag: {supported: false}
}));

describe(".endpoint", ResourcesHooks.endpoint(ServiceProviderConfig));
describe(".schema", ResourcesHooks.schema(ServiceProviderConfig, false));
describe(".basepath()", ResourcesHooks.basepath(ServiceProviderConfig));
describe(".extend()", ResourcesHooks.extend(ServiceProviderConfig, true));
describe(".ingress()", ResourcesHooks.ingress(ServiceProviderConfig, false));
describe(".egress()", ResourcesHooks.egress(ServiceProviderConfig, false));
describe(".degress()", ResourcesHooks.degress(ServiceProviderConfig, false));
describe("@constructor", ResourcesHooks.construct(ServiceProviderConfig, false));
describe("#read()", ResourcesHooks.read(ServiceProviderConfig, fixtures, false));
describe("#write()", ResourcesHooks.write(ServiceProviderConfig, false));
describe("#patch()", ResourcesHooks.patch(ServiceProviderConfig, false));
describe("#dispose()", ResourcesHooks.dispose(ServiceProviderConfig, false));
describe(".schema", hooks.schema(false));
describe(".endpoint", hooks.endpoint());
describe(".basepath()", hooks.basepath());
describe(".extend()", hooks.extend(false));
describe(".ingress()", hooks.ingress(false));
describe(".egress()", hooks.egress(false));
describe(".degress()", hooks.degress(false));
describe("@constructor", hooks.construct(false));
describe("#read()", hooks.read(false));
describe("#write()", hooks.write(false));
describe("#patch()", hooks.patch(false));
describe("#dispose()", hooks.dispose(false));
});
26 changes: 14 additions & 12 deletions test/lib/resources/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./user.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Resources.User", () => {
describe(".endpoint", ResourcesHooks.endpoint(User));
describe(".schema", ResourcesHooks.schema(User));
describe(".basepath()", ResourcesHooks.basepath(User));
describe(".extend()", ResourcesHooks.extend(User, false));
describe(".ingress()", ResourcesHooks.ingress(User, fixtures));
describe(".egress()", ResourcesHooks.egress(User, fixtures));
describe(".degress()", ResourcesHooks.degress(User, fixtures));
describe("@constructor", ResourcesHooks.construct(User));
describe("#read()", ResourcesHooks.read(User, fixtures));
describe("#write()", ResourcesHooks.write(User, fixtures));
describe("#patch()", ResourcesHooks.patch(User, fixtures));
describe("#dispose()", ResourcesHooks.dispose(User, fixtures));
const hooks = new ResourcesHooks(User, fixtures);

describe(".schema", hooks.schema(true));
describe(".endpoint", hooks.endpoint());
describe(".basepath()", hooks.basepath());
describe(".extend()", hooks.extend(true));
describe(".ingress()", hooks.ingress(true));
describe(".egress()", hooks.egress(true));
describe(".degress()", hooks.degress(true));
describe("@constructor", hooks.construct(true));
describe("#read()", hooks.read(true, true));
describe("#write()", hooks.write(true));
describe("#patch()", hooks.patch(true));
describe("#dispose()", hooks.dispose(true));
});
6 changes: 4 additions & 2 deletions test/lib/schemas/enterpriseuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./enterpriseuser.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Schemas.EnterpriseUser", () => {
describe(".definition", SchemasHooks.definition(EnterpriseUser, fixtures));
describe("@constructor", SchemasHooks.construct(EnterpriseUser, fixtures));
const hooks = new SchemasHooks(EnterpriseUser, fixtures);

describe(".definition", hooks.definition());
describe("@constructor", hooks.construct());
});
6 changes: 4 additions & 2 deletions test/lib/schemas/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./group.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Schemas.Group", () => {
describe(".definition", SchemasHooks.definition(Group, fixtures));
describe("@constructor", SchemasHooks.construct(Group, fixtures));
const hooks = new SchemasHooks(Group, fixtures);

describe(".definition", hooks.definition());
describe("@constructor", hooks.construct());
});
6 changes: 4 additions & 2 deletions test/lib/schemas/resourcetype.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./resourcetype.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Schemas.ResourceType", () => {
describe(".definition", SchemasHooks.definition(ResourceType, fixtures));
describe("@constructor", SchemasHooks.construct(ResourceType, fixtures));
const hooks = new SchemasHooks(ResourceType, fixtures);

describe(".definition", hooks.definition());
describe("@constructor", hooks.construct());
});
6 changes: 4 additions & 2 deletions test/lib/schemas/spconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./spconfig.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Schemas.ServiceProviderConfig", () => {
describe(".definition", SchemasHooks.definition(ServiceProviderConfig, fixtures));
describe("@constructor", SchemasHooks.construct(ServiceProviderConfig, fixtures));
const hooks = new SchemasHooks(ServiceProviderConfig, fixtures);

describe(".definition", hooks.definition());
describe("@constructor", hooks.construct());
});
6 changes: 4 additions & 2 deletions test/lib/schemas/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const basepath = path.relative(process.cwd(), path.dirname(url.fileURLToPath(imp
const fixtures = fs.readFile(path.join(basepath, "./user.json"), "utf8").then((f) => JSON.parse(f));

describe("SCIMMY.Schemas.User", () => {
describe(".definition", SchemasHooks.definition(User, fixtures));
describe("@constructor", SchemasHooks.construct(User, fixtures));
const hooks = new SchemasHooks(User, fixtures);

describe(".definition", hooks.definition());
describe("@constructor", hooks.construct());
});
2 changes: 1 addition & 1 deletion test/lib/types/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("SCIMMY.Types.Schema", () => {
});

describe("@constructor", () => {
SchemasHooks.construct(createSchemaClass({attributes: [new Attribute("string", "aString")]}), fixtures).call();
new SchemasHooks(createSchemaClass({attributes: [new Attribute("string", "aString")]}), fixtures).construct().call();

it("should include 'toJSON' method that strips attributes where returned is marked as 'never'", async () => {
const attributes = [new Attribute("string", "aValue"), new Attribute("string", "aString", {returned: false})];
Expand Down

0 comments on commit 0fa9bf7

Please sign in to comment.