Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api-headless-cms): dates in entry input #3718

Merged
merged 18 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c0dda6a
fix(api-headless-cms): dates in entry input
brunozoric Nov 22, 2023
c635c8f
fix(api-headless-cms): graphql scheme snapshots in tests
brunozoric Nov 22, 2023
5dc0b90
fix(api-headless-cms): entry input types
brunozoric Nov 22, 2023
77db618
test(api-aco): add missing date fields into snapshots
brunozoric Nov 22, 2023
b1f1a40
fix(api-apw): add savedOn into apw storage ops on each update method
brunozoric Nov 22, 2023
c10b7cd
fix(api-file-manager): add missing date fields into snapshots
brunozoric Nov 22, 2023
798900b
fix(api-file-manager): add dates into storage ops
brunozoric Nov 22, 2023
e92f9b2
fix(api-headless-cms): date formatting
brunozoric Nov 22, 2023
2404f6b
test(api-headless-cms): custom dates
brunozoric Nov 23, 2023
23479bb
test(api-file-manager): custom dates
brunozoric Nov 23, 2023
4c1e01d
fix(api-headless-cms): snapshots
brunozoric Nov 23, 2023
64ed909
fix(api-headless-cms): republish method
brunozoric Nov 23, 2023
b1abf08
fix(api-headless-cms): keep existing logic when creating entry form a…
brunozoric Nov 23, 2023
626ed88
fix(api-headless-cms): add createdBy, modifiedBy and ownedBy into ent…
brunozoric Nov 23, 2023
2c35c32
fix(api-file-manager): add createdBy and modifiedBy into file methods
brunozoric Nov 23, 2023
dd45ea0
fix(api-headless-cms): types
brunozoric Nov 23, 2023
f9cbc87
fix(api-headless-cms): comments about skipping publishedOn and savedOn
brunozoric Nov 23, 2023
a9b57f0
Merge branch 'dev' into bruno/fix/api-headless-cms/dates-in-entry-input
Pavel910 Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/api-aco/__tests__/snapshots/customAppsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ export const createCustomAppsSchemaSnapshot = () => {
savedOn_lte: DateTime
savedOn_between: [DateTime!]
savedOn_not_between: [DateTime!]
publishedOn: DateTime
publishedOn_gt: DateTime
publishedOn_gte: DateTime
publishedOn_lt: DateTime
publishedOn_lte: DateTime
publishedOn_between: [DateTime!]
publishedOn_not_between: [DateTime!]
createdBy: String
createdBy_not: String
createdBy_in: [String!]
Expand Down
7 changes: 7 additions & 0 deletions packages/api-aco/__tests__/snapshots/defaultAppsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ export const createDefaultAppsSchemaSnapshot = () => {
savedOn_lte: DateTime
savedOn_between: [DateTime!]
savedOn_not_between: [DateTime!]
publishedOn: DateTime
publishedOn_gt: DateTime
publishedOn_gte: DateTime
publishedOn_lt: DateTime
publishedOn_lte: DateTime
publishedOn_between: [DateTime!]
publishedOn_not_between: [DateTime!]
createdBy: String
createdBy_not: String
createdBy_in: [String!]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export const createChangeRequestStorageOperations = (
const entry = await security.withoutAuthorization(async () => {
return cms.updateEntry(model, params.id, {
...existingEntry,
...params.data
...params.data,
savedOn: new Date()
});
});
return getFieldValues({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export const createCommentStorageOperations = ({
const entry = await security.withoutAuthorization(async () => {
return cms.updateEntry(model, params.id, {
...existingEntry,
...params.data
...params.data,
savedOn: new Date()
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const createContentReviewStorageOperations = ({
const entry = await security.withoutAuthorization(async () => {
return cms.updateEntry(model, params.id, {
...existingEntry,
...params.data
...params.data,
savedOn: new Date()
});
});
return getFieldValues(entry, baseFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const createReviewerStorageOperations = ({
const entry = await security.withoutAuthorization(async () => {
return cms.updateEntry(model, params.id, {
...existingEntry,
...params.data
...params.data,
savedOn: new Date()
});
});
return getFieldValues(entry, baseFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const createWorkflowStorageOperations = (
const existingEntry = await getWorkflow({ id: params.id });
const input = {
...existingEntry,
...params.data
...params.data,
savedOn: new Date()
};
const data = formatReviewersForRefInput(
input as CreateApwWorkflowParams,
Expand Down
58 changes: 58 additions & 0 deletions packages/api-file-manager/__tests__/file.customDates.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import useGqlHandler from "./utils/useGqlHandler";
import { fileAData, ids } from "./mocks/files";

describe("file custom dates", () => {
const { createFile, updateFile } = useGqlHandler();

it("should create and update file with custom dates", async () => {
const [createResponse] = await createFile(
{
data: {
...fileAData,
createdOn: "1995-01-01T00:00:00.000Z",
savedOn: "1995-01-01T00:00:00.000Z"
}
},
["createdOn", "savedOn"]
);
expect(createResponse).toEqual({
data: {
fileManager: {
createFile: {
data: {
...fileAData,
createdOn: "1995-01-01T00:00:00.000Z",
savedOn: "1995-01-01T00:00:00.000Z"
},
error: null
}
}
}
});

const [updateResponse] = await updateFile(
{
id: ids.A,
data: {
createdOn: "2005-01-01T00:00:00.000Z",
savedOn: "2005-01-01T00:00:00.000Z"
}
},
["createdOn", "savedOn"]
);
expect(updateResponse).toEqual({
data: {
fileManager: {
updateFile: {
data: {
...fileAData,
createdOn: "2005-01-01T00:00:00.000Z",
savedOn: "2005-01-01T00:00:00.000Z"
},
error: null
}
}
}
});
});
});
107 changes: 107 additions & 0 deletions packages/api-file-manager/__tests__/file.customIdentities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import useGqlHandler from "./utils/useGqlHandler";
import { fileAData } from "./mocks/files";
import { SecurityIdentity } from "@webiny/api-security/types";

const extraFields = ["createdBy {id displayName type}", "modifiedBy {id displayName type}"];
describe("file custom identities", () => {
const { createFile, updateFile, identity: defaultIdentity } = useGqlHandler();

const mockIdentityOne: SecurityIdentity = {
id: "mock-identity-one",
displayName: "Mock Identity One",
type: "mockOne"
};
const mockIdentityTwo: SecurityIdentity = {
id: "mock-identity-two",
displayName: "Mock Identity Two",
type: "mockTwo"
};

it("should create a file with custom identity", async () => {
const [createRegularResponse] = await createFile(
{
data: {
...fileAData
}
},
extraFields
);
expect(createRegularResponse).toEqual({
data: {
fileManager: {
createFile: {
data: {
...fileAData,
createdBy: defaultIdentity,
modifiedBy: null
},
error: null
}
}
}
});

const [createCustomIdentityResponse] = await createFile(
{
data: {
...fileAData,
createdBy: mockIdentityOne,
modifiedBy: mockIdentityTwo
}
},
extraFields
);
expect(createCustomIdentityResponse).toEqual({
data: {
fileManager: {
createFile: {
data: {
...fileAData,
createdBy: mockIdentityOne,
modifiedBy: mockIdentityTwo
},
error: null
}
}
}
});
});

it("should update a file with custom identity", async () => {
const [createResponse] = await createFile(
{
data: {
...fileAData
}
},
extraFields
);

const id = createResponse.data.fileManager.createFile.data.id;

const [updateResponse] = await updateFile(
{
id,
data: {
createdBy: mockIdentityOne,
modifiedBy: mockIdentityTwo
}
},
extraFields
);
expect(updateResponse).toEqual({
data: {
fileManager: {
updateFile: {
data: {
...fileAData,
createdBy: mockIdentityOne,
modifiedBy: mockIdentityTwo
},
error: null
}
}
}
});
});
});
10 changes: 6 additions & 4 deletions packages/api-file-manager/__tests__/file.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("File lifecycle events", () => {
* Parameters that were received in the lifecycle hooks must be valid as well.
*/
const beforeCreate = tracker.getLast("file:beforeCreate");
expect(beforeCreate && beforeCreate.params[0]).toEqual({
expect(beforeCreate && beforeCreate.params[0]).toMatchObject({
file: {
...fileData,
...hookParamsExpected,
Expand All @@ -88,7 +88,7 @@ describe("File lifecycle events", () => {
}
});
const afterCreate = tracker.getLast("file:beforeCreate");
expect(afterCreate && afterCreate.params[0]).toEqual({
expect(afterCreate && afterCreate.params[0]).toMatchObject({
file: {
...fileData,
...hookParamsExpected,
Expand Down Expand Up @@ -138,7 +138,7 @@ describe("File lifecycle events", () => {
* Parameters that were received in the lifecycle hooks must be valid as well.
*/
const beforeUpdate = tracker.getLast("file:beforeUpdate");
expect(beforeUpdate && beforeUpdate.params[0]).toEqual({
expect(beforeUpdate && beforeUpdate.params[0]).toMatchObject({
input: { tags: [...fileData.tags, TAG] },
original: {
...fileData,
Expand All @@ -160,7 +160,7 @@ describe("File lifecycle events", () => {
}
});
const afterUpdate = tracker.getLast("file:afterUpdate");
expect(afterUpdate && afterUpdate.params[0]).toEqual({
expect(afterUpdate && afterUpdate.params[0]).toMatchObject({
input: { tags: [...fileData.tags, TAG] },
original: {
...fileData,
Expand Down Expand Up @@ -219,6 +219,7 @@ describe("File lifecycle events", () => {
file: {
...fileData,
...hookParamsExpected,
modifiedBy: null,
location: {
folderId: ROOT_FOLDER
},
Expand All @@ -230,6 +231,7 @@ describe("File lifecycle events", () => {
file: {
...fileData,
...hookParamsExpected,
modifiedBy: null,
location: {
folderId: ROOT_FOLDER
},
Expand Down
22 changes: 22 additions & 0 deletions packages/api-file-manager/__tests__/mocks/file.sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default /* GraphQL */ `
savedOn: DateTime!
createdOn: DateTime!
createdBy: FmCreatedBy!
modifiedBy: FmCreatedBy
src: String
location: FmFile_Location
name: String
Expand Down Expand Up @@ -127,8 +128,18 @@ export default /* GraphQL */ `
article: RefFieldInput
}

input FmCreatedByInput {
id: ID!
displayName: String!
type: String!
}

input FmFileCreateInput {
id: ID!
createdOn: DateTime
savedOn: DateTime
createdBy: FmCreatedByInput
modifiedBy: FmCreatedByInput
location: FmFile_LocationInput
name: String
key: String
Expand All @@ -141,6 +152,10 @@ export default /* GraphQL */ `
}

input FmFileUpdateInput {
createdOn: DateTime
savedOn: DateTime
createdBy: FmCreatedByInput
modifiedBy: FmCreatedByInput
location: FmFile_LocationInput
name: String
key: String
Expand Down Expand Up @@ -176,6 +191,13 @@ export default /* GraphQL */ `
savedOn_lte: DateTime
savedOn_between: [DateTime!]
savedOn_not_between: [DateTime!]
publishedOn: DateTime
publishedOn_gt: DateTime
publishedOn_gte: DateTime
publishedOn_lt: DateTime
publishedOn_lte: DateTime
publishedOn_between: [DateTime!]
publishedOn_not_between: [DateTime!]
createdBy: String
createdBy_not: String
createdBy_in: [String!]
Expand Down
14 changes: 7 additions & 7 deletions packages/api-file-manager/__tests__/utils/tenancySecurity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ interface Config {
identity?: SecurityIdentity | null;
}

export const defaultIdentity: SecurityIdentity = {
id: "12345678",
type: "admin",
displayName: "John Doe"
};

export const createTenancyAndSecurity = ({ permissions, identity }: Config) => {
const securityStorage = getStorageOps<SecurityStorageOperations>("security");
const tenancyStorage = getStorageOps<TenancyStorageOperations>("tenancy");
Expand All @@ -41,13 +47,7 @@ export const createTenancyAndSecurity = ({ permissions, identity }: Config) => {
});

context.security.addAuthenticator(async () => {
return (
identity || {
id: "12345678",
type: "admin",
displayName: "John Doe"
}
);
return identity || defaultIdentity;
});

context.security.addAuthorizer(async () => {
Expand Down
Loading