Skip to content

Commit

Permalink
fix: allow for one to one relationship requests - comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jac-moran committed Sep 3, 2024
1 parent a23ecea commit 95cbcff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,56 @@ describe("resource object rules", () => {
},
);

test.each(["uuid", "uri", "ulid"])(
"passes when PATCH request body for a relationship is of the correct form (data is an collection of resource objects with id and type)",
async (format) => {
const afterJson = {
...baseJson,
paths: {
"/api/example/relationships/example": {
patch: {
responses: {}, // not tested here
requestBody: {
content: {
"application/vnd.api+json": {
schema: {
type: "object",
properties: {
data: {
type: "array",
items: {
type: "object",
properties: {
type: {
type: "string",
},
id: {
type: "string",
format: format,
},
},
},
},
},
},
},
},
},
},
},
},
} as OpenAPIV3.Document;
const ruleRunner = new RuleRunner([resourceObjectRules]);
const ruleInputs = {
...TestHelpers.createRuleInputs(baseJson, afterJson),
context,
};
const results = await ruleRunner.runRulesWithFacts(ruleInputs);
expect(results.length).toBeGreaterThan(0);
expect(results.every((result) => result.passed)).toBe(true);
},
);

test.each(["uuid", "uri", "ulid"])(
"passes when PATCH request body for a relationship is of the correct form (data is a single resource object with id and type)",
async (format) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const requestDataForPost = new RequestRule({
},
});

// Relationship POST, PATCH, and DELETE requests must have
// Relationship POST, PATCH, and DELETE requests can have
// a request body with resource objects for the relationships
// to be added/patched/deleted.
const matchRelationshipModificationRequestArrayData = {
Expand All @@ -142,9 +142,9 @@ const matchRelationshipModificationRequestArrayData = {
},
};

// Relationship POST, PATCH, and DELETE requests must have
// a request body with resource objects for the relationships
// to be added/patched/deleted.
// Relationship POST, PATCH, and DELETE requests can have
// a request body with a resource object for the single relationship
// to be added (set)/patched/deleted.
const matchRelationshipModificationRequestSingleData = {
data: {
type: "object",
Expand Down

0 comments on commit 95cbcff

Please sign in to comment.