mirror of
https://github.com/outline/outline.git
synced 2026-08-03 13:27:25 +03:00
fix tests
This commit is contained in:
@@ -27,7 +27,7 @@ import ShareSettingsPopover from "../components/ShareSettingsPopover";
|
||||
import { DomainPrefix, ShareLinkInput, StyledInfoIcon } from "../components";
|
||||
import styled from "styled-components";
|
||||
import { s } from "@shared/styles";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
type Props = {
|
||||
/** The collection to share. */
|
||||
@@ -50,7 +50,7 @@ function InnerPublicAccess(
|
||||
const collectionAbilities = usePolicy(collection);
|
||||
const canPublish = share ? can.update : collectionAbilities.share;
|
||||
const [creating, setCreating] = React.useState(false);
|
||||
const isShareExpired = share?.expiresAt && !isAfterToday(share.expiresAt);
|
||||
const isShareExpired = share?.expiresAt && !isFuture(share.expiresAt);
|
||||
|
||||
React.useEffect(() => {
|
||||
setUrlId(share?.urlId);
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
StyledInfoIcon,
|
||||
UnderlinedLink,
|
||||
} from "../components";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
type Props = {
|
||||
/** The document to share. */
|
||||
@@ -59,9 +59,9 @@ function PublicAccess(
|
||||
const documentAbilities = usePolicy(document);
|
||||
const canPublish = share ? can.update : documentAbilities.share;
|
||||
const [creating, setCreating] = React.useState(false);
|
||||
const isShareExpired = share?.expiresAt && !isAfterToday(share.expiresAt);
|
||||
const isShareExpired = share?.expiresAt && !isFuture(share.expiresAt);
|
||||
const isParentShareExpired =
|
||||
sharedParent?.expiresAt && !isAfterToday(sharedParent.expiresAt);
|
||||
sharedParent?.expiresAt && !isFuture(sharedParent.expiresAt);
|
||||
|
||||
const hasExpiredShare =
|
||||
(!!share?.published && isShareExpired) ||
|
||||
|
||||
@@ -15,7 +15,7 @@ import useShareDataLoader from "~/hooks/useShareDataLoader";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { preventDefault } from "~/utils/events";
|
||||
import lazyWithRetry from "~/utils/lazyWithRetry";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
const SharePopover = lazyWithRetry(
|
||||
() => import("~/components/Sharing/Collection/SharePopover")
|
||||
@@ -33,7 +33,7 @@ function ShareButton({ collection }: Props) {
|
||||
const isMobile = useMobile();
|
||||
const team = useCurrentTeam();
|
||||
const share = shares.getByCollectionId(collection.id);
|
||||
const isShareExpired = share?.expiresAt && !isAfterToday(share.expiresAt);
|
||||
const isShareExpired = share?.expiresAt && !isFuture(share.expiresAt);
|
||||
const isPubliclyShared =
|
||||
team.sharing !== false &&
|
||||
collection?.sharing !== false &&
|
||||
|
||||
@@ -14,7 +14,7 @@ import useShareDataLoader from "~/hooks/useShareDataLoader";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { preventDefault } from "~/utils/events";
|
||||
import lazyWithRetry from "~/utils/lazyWithRetry";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
const SharePopover = lazyWithRetry(
|
||||
() => import("~/components/Sharing/Document")
|
||||
@@ -33,9 +33,9 @@ function ShareButton({ document }: Props) {
|
||||
const share = shares.getByDocumentId(document.id);
|
||||
const sharedParent = shares.getByDocumentParents(document);
|
||||
const domain = share?.domain || sharedParent?.domain;
|
||||
const isShareExpired = share?.expiresAt && !isAfterToday(share.expiresAt);
|
||||
const isShareExpired = share?.expiresAt && !isFuture(share.expiresAt);
|
||||
const isParentShareExpired =
|
||||
sharedParent?.expiresAt && !isAfterToday(sharedParent.expiresAt);
|
||||
sharedParent?.expiresAt && !isFuture(sharedParent.expiresAt);
|
||||
const hasActiveShare = !!share?.published && !isShareExpired;
|
||||
const hasActiveParentShare =
|
||||
!!sharedParent?.published && !isParentShareExpired;
|
||||
|
||||
@@ -6,12 +6,13 @@ import {
|
||||
buildViewer,
|
||||
} from "@server/test/factories";
|
||||
import { getTestServer } from "@server/test/support";
|
||||
import { addMonths } from "date-fns";
|
||||
|
||||
const server = getTestServer();
|
||||
|
||||
describe("#apiKeys.create", () => {
|
||||
it("should allow creating an api key with expiry", async () => {
|
||||
const now = new Date();
|
||||
const now = addMonths(new Date(), 1);
|
||||
const user = await buildUser();
|
||||
|
||||
const res = await server.post("/api/apiKeys.create", user, {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import { ApiKey } from "@server/models";
|
||||
import { BaseSchema } from "@server/routes/api/schema";
|
||||
import { ApiKeyValidation } from "@shared/validations";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
export const APIKeysCreateSchema = BaseSchema.extend({
|
||||
body: z.object({
|
||||
@@ -16,7 +16,7 @@ export const APIKeysCreateSchema = BaseSchema.extend({
|
||||
expiresAt: z.coerce
|
||||
.date()
|
||||
.optional()
|
||||
.refine((value) => !value || isAfterToday(value), {
|
||||
.refine((value) => !value || isFuture(value), {
|
||||
error: "must be in the future",
|
||||
}),
|
||||
/** A list of scopes that this API key has access to */
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Share } from "@server/models";
|
||||
import { ValidateURL } from "@server/validation";
|
||||
import { zodIdType } from "@server/utils/zod";
|
||||
import { BaseSchema } from "../schema";
|
||||
import { isAfterToday } from "@shared/utils/date";
|
||||
import { isFuture } from "date-fns";
|
||||
|
||||
export const SharesInfoSchema = BaseSchema.extend({
|
||||
body: z
|
||||
@@ -37,9 +37,7 @@ export const SharesListSchema = BaseSchema.extend({
|
||||
sort: z
|
||||
.string()
|
||||
.refine((val) => Object.keys(Share.getAttributes()).includes(val), {
|
||||
message: `must be one of ${Object.keys(Share.getAttributes()).join(
|
||||
", "
|
||||
)}`,
|
||||
message: `must be one of ${Object.keys(Share.getAttributes()).join(", ")}`,
|
||||
})
|
||||
.prefault("updatedAt"),
|
||||
direction: z
|
||||
@@ -57,7 +55,7 @@ export const SharesUpdateSchema = BaseSchema.extend({
|
||||
expiresAt: z.coerce
|
||||
.date()
|
||||
.nullish()
|
||||
.refine((value) => !value || isAfterToday(value), {
|
||||
.refine((value) => !value || isFuture(value), {
|
||||
error: "must be in the future",
|
||||
}),
|
||||
includeChildDocuments: z.boolean().optional(),
|
||||
@@ -94,7 +92,7 @@ export const SharesCreateSchema = BaseSchema.extend({
|
||||
expiresAt: z.coerce
|
||||
.date()
|
||||
.optional()
|
||||
.refine((value) => !value || isAfterToday(value), {
|
||||
.refine((value) => !value || isFuture(value), {
|
||||
error: "must be in the future",
|
||||
}),
|
||||
published: z.boolean().prefault(false),
|
||||
|
||||
@@ -479,6 +479,7 @@
|
||||
"Allow viewers to subscribe and receive email notifications when documents are updated": "Allow viewers to subscribe and receive email notifications when documents are updated",
|
||||
"Link Expiration": "Link Expiration",
|
||||
"Set an expiration date for the link": "Set an expiration date for the link",
|
||||
"Expiration": "Expiration",
|
||||
"Never expires": "Never expires",
|
||||
"Something went wrong": "Something went wrong",
|
||||
"Check your email to confirm your subscription": "Check your email to confirm your subscription",
|
||||
@@ -763,7 +764,6 @@
|
||||
"API key created. Please copy the value now as it will not be shown again.": "API key created. Please copy the value now as it will not be shown again.",
|
||||
"Scopes": "Scopes",
|
||||
"Space-separated scopes restrict the access of this API key to specific parts of the API. Leave blank for full access": "Space-separated scopes restrict the access of this API key to specific parts of the API. Leave blank for full access",
|
||||
"Expiration": "Expiration",
|
||||
"7 days": "7 days",
|
||||
"30 days": "30 days",
|
||||
"60 days": "60 days",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
dateToReadable,
|
||||
dateToRelativeReadable,
|
||||
isAfterToday,
|
||||
parseISODate,
|
||||
toISODate,
|
||||
} from "./date";
|
||||
@@ -79,28 +78,3 @@ describe("dateToRelativeReadable", () => {
|
||||
expect(dateToRelativeReadable("2020-02-03", t)).toBe("February 3rd, 2020");
|
||||
});
|
||||
});
|
||||
|
||||
describe("isAfterToday", () => {
|
||||
it("returns true for a future date", () => {
|
||||
const future = new Date();
|
||||
future.setDate(future.getDate() + 1);
|
||||
expect(isAfterToday(future)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for a past date", () => {
|
||||
const past = new Date();
|
||||
past.setDate(past.getDate() - 1);
|
||||
expect(isAfterToday(past)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for today", () => {
|
||||
const today = new Date();
|
||||
expect(isAfterToday(today)).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts an ISO string", () => {
|
||||
const future = new Date();
|
||||
future.setDate(future.getDate() + 7);
|
||||
expect(isAfterToday(future.toISOString())).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -394,16 +394,3 @@ export function dateToRelativeReadable(
|
||||
}
|
||||
return format(date, "MMMM do, yyyy", { locale });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when the given date is in the future relative to now.
|
||||
*
|
||||
* @param value - the date to test, either a Date object or an ISO string.
|
||||
* @returns true if the date is in the future, false otherwise.
|
||||
*/
|
||||
export function isAfterToday(value: Date | string): boolean {
|
||||
const now = new Date();
|
||||
const candidate = new Date(value);
|
||||
|
||||
return candidate > now;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user