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

Update reservationUnit state properties as per backend changes #1376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions apps/admin-ui/src/component/reservation-units/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const SEARCH_RESERVATION_UNITS_QUERY = gql`
$unit: [Int]
$reservationUnitType: [Int]
$orderBy: [ReservationUnitOrderingChoices]
$state: [ReservationUnitState]
$publishingState: [ReservationUnitPublishingState]
) {
reservationUnits(
first: $first
Expand All @@ -27,7 +27,7 @@ export const SEARCH_RESERVATION_UNITS_QUERY = gql`
surfaceAreaLte: $surfaceAreaLte
unit: $unit
reservationUnitType: $reservationUnitType
state: $state
publishingState: $publishingState
onlyWithPermission: true
) {
edges {
Expand All @@ -46,7 +46,7 @@ export const SEARCH_RESERVATION_UNITS_QUERY = gql`
}
maxPersons
surfaceArea
state
publishingState
reservationState
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/admin-ui/src/spa/ReservationUnit/edit/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const RESERVATION_UNIT_EDIT_QUERY = gql`
reservationUnit(id: $id) {
id
pk
state
publishingState
reservationState
images {
pk
Expand Down
74 changes: 45 additions & 29 deletions apps/ui/gql/gql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ export type ApplicationRoundNodeReservationUnitsArgs = {
onlyWithPermission?: InputMaybe<Scalars["Boolean"]["input"]>;
orderBy?: InputMaybe<Array<InputMaybe<ReservationUnitOrderingChoices>>>;
pk?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
publishingState?: InputMaybe<
Array<InputMaybe<ReservationUnitPublishingState>>
>;
purposes?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
qualifiers?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
rankGte?: InputMaybe<Scalars["Decimal"]["input"]>;
Expand All @@ -414,10 +417,11 @@ export type ApplicationRoundNodeReservationUnitsArgs = {
reservableTimeEnd?: InputMaybe<Scalars["Time"]["input"]>;
reservableTimeStart?: InputMaybe<Scalars["Time"]["input"]>;
reservationKind?: InputMaybe<Scalars["String"]["input"]>;
reservationState?: InputMaybe<Array<InputMaybe<ReservationState>>>;
reservationState?: InputMaybe<
Array<InputMaybe<ReservationUnitReservationState>>
>;
reservationUnitType?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
showOnlyReservable?: InputMaybe<Scalars["Boolean"]["input"]>;
state?: InputMaybe<Array<InputMaybe<ReservationUnitState>>>;
surfaceAreaGte?: InputMaybe<Scalars["Decimal"]["input"]>;
surfaceAreaLte?: InputMaybe<Scalars["Decimal"]["input"]>;
textSearch?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -2296,6 +2300,9 @@ export type QueryReservationUnitsArgs = {
onlyWithPermission?: InputMaybe<Scalars["Boolean"]["input"]>;
orderBy?: InputMaybe<Array<InputMaybe<ReservationUnitOrderingChoices>>>;
pk?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
publishingState?: InputMaybe<
Array<InputMaybe<ReservationUnitPublishingState>>
>;
purposes?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
qualifiers?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
rankGte?: InputMaybe<Scalars["Decimal"]["input"]>;
Expand All @@ -2306,10 +2313,11 @@ export type QueryReservationUnitsArgs = {
reservableTimeEnd?: InputMaybe<Scalars["Time"]["input"]>;
reservableTimeStart?: InputMaybe<Scalars["Time"]["input"]>;
reservationKind?: InputMaybe<Scalars["String"]["input"]>;
reservationState?: InputMaybe<Array<InputMaybe<ReservationState>>>;
reservationState?: InputMaybe<
Array<InputMaybe<ReservationUnitReservationState>>
>;
reservationUnitType?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
showOnlyReservable?: InputMaybe<Scalars["Boolean"]["input"]>;
state?: InputMaybe<Array<InputMaybe<ReservationUnitState>>>;
surfaceAreaGte?: InputMaybe<Scalars["Decimal"]["input"]>;
surfaceAreaLte?: InputMaybe<Scalars["Decimal"]["input"]>;
textSearch?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -3112,6 +3120,9 @@ export type ReservationNodeReservationUnitArgs = {
onlyWithPermission?: InputMaybe<Scalars["Boolean"]["input"]>;
orderBy?: InputMaybe<Array<InputMaybe<ReservationUnitOrderingChoices>>>;
pk?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
publishingState?: InputMaybe<
Array<InputMaybe<ReservationUnitPublishingState>>
>;
purposes?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
qualifiers?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
rankGte?: InputMaybe<Scalars["Decimal"]["input"]>;
Expand All @@ -3122,10 +3133,11 @@ export type ReservationNodeReservationUnitArgs = {
reservableTimeEnd?: InputMaybe<Scalars["Time"]["input"]>;
reservableTimeStart?: InputMaybe<Scalars["Time"]["input"]>;
reservationKind?: InputMaybe<Scalars["String"]["input"]>;
reservationState?: InputMaybe<Array<InputMaybe<ReservationState>>>;
reservationState?: InputMaybe<
Array<InputMaybe<ReservationUnitReservationState>>
>;
reservationUnitType?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
showOnlyReservable?: InputMaybe<Scalars["Boolean"]["input"]>;
state?: InputMaybe<Array<InputMaybe<ReservationUnitState>>>;
surfaceAreaGte?: InputMaybe<Scalars["Decimal"]["input"]>;
surfaceAreaLte?: InputMaybe<Scalars["Decimal"]["input"]>;
textSearch?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -3525,15 +3537,6 @@ export enum ReservationStartInterval {
Interval_420Mins = "INTERVAL_420_MINS",
}

/** An enumeration. */
export enum ReservationState {
Reservable = "RESERVABLE",
ReservationClosed = "RESERVATION_CLOSED",
ScheduledClosing = "SCHEDULED_CLOSING",
ScheduledPeriod = "SCHEDULED_PERIOD",
ScheduledReservation = "SCHEDULED_RESERVATION",
}

/** An enumeration. */
export enum ReservationStateChoice {
Cancelled = "CANCELLED",
Expand Down Expand Up @@ -3712,6 +3715,7 @@ export type ReservationUnitCreateMutationPayload = {
pricings?: Maybe<Array<Maybe<ReservationUnitPricingNode>>>;
publishBegins?: Maybe<Scalars["DateTime"]["output"]>;
publishEnds?: Maybe<Scalars["DateTime"]["output"]>;
publishingState?: Maybe<Scalars["String"]["output"]>;
purposes?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
qualifiers?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
requireIntroduction?: Maybe<Scalars["Boolean"]["output"]>;
Expand Down Expand Up @@ -3740,7 +3744,6 @@ export type ReservationUnitCreateMutationPayload = {
serviceSpecificTerms?: Maybe<Scalars["String"]["output"]>;
services?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
spaces?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
state?: Maybe<Scalars["String"]["output"]>;
surfaceArea?: Maybe<Scalars["Int"]["output"]>;
termsOfUse?: Maybe<Scalars["String"]["output"]>;
termsOfUseEn?: Maybe<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -3846,6 +3849,7 @@ export type ReservationUnitNode = Node & {
pricings: Array<ReservationUnitPricingNode>;
publishBegins?: Maybe<Scalars["DateTime"]["output"]>;
publishEnds?: Maybe<Scalars["DateTime"]["output"]>;
publishingState?: Maybe<ReservationUnitPublishingState>;
purposes: Array<PurposeNode>;
qualifiers: Array<QualifierNode>;
rank?: Maybe<Scalars["Int"]["output"]>;
Expand All @@ -3870,15 +3874,14 @@ export type ReservationUnitNode = Node & {
reservationPendingInstructionsSv?: Maybe<Scalars["String"]["output"]>;
reservationSet?: Maybe<Array<ReservationNode>>;
reservationStartInterval: ReservationStartInterval;
reservationState?: Maybe<ReservationState>;
reservationState?: Maybe<ReservationUnitReservationState>;
reservationUnitType?: Maybe<ReservationUnitTypeNode>;
reservationsMaxDaysBefore?: Maybe<Scalars["Int"]["output"]>;
reservationsMinDaysBefore?: Maybe<Scalars["Int"]["output"]>;
resources: Array<ResourceNode>;
serviceSpecificTerms?: Maybe<TermsOfUseNode>;
services: Array<ServiceNode>;
spaces: Array<SpaceNode>;
state?: Maybe<ReservationUnitState>;
surfaceArea?: Maybe<Scalars["Int"]["output"]>;
termsOfUse?: Maybe<Scalars["String"]["output"]>;
termsOfUseEn?: Maybe<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -4142,7 +4145,7 @@ export type ReservationUnitPricingSerializerInput = {
};

/** An enumeration. */
export enum ReservationUnitState {
export enum ReservationUnitPublishingState {
Archived = "ARCHIVED",
Draft = "DRAFT",
Hidden = "HIDDEN",
Expand All @@ -4152,6 +4155,15 @@ export enum ReservationUnitState {
ScheduledPublishing = "SCHEDULED_PUBLISHING",
}

/** An enumeration. */
export enum ReservationUnitReservationState {
Reservable = "RESERVABLE",
ReservationClosed = "RESERVATION_CLOSED",
ScheduledClosing = "SCHEDULED_CLOSING",
ScheduledPeriod = "SCHEDULED_PERIOD",
ScheduledReservation = "SCHEDULED_RESERVATION",
}

export type ReservationUnitTypeNode = Node & {
/** The ID of the object */
id: Scalars["ID"]["output"];
Expand Down Expand Up @@ -4306,6 +4318,7 @@ export type ReservationUnitUpdateMutationPayload = {
pricings?: Maybe<Array<Maybe<ReservationUnitPricingNode>>>;
publishBegins?: Maybe<Scalars["DateTime"]["output"]>;
publishEnds?: Maybe<Scalars["DateTime"]["output"]>;
publishingState?: Maybe<Scalars["String"]["output"]>;
purposes?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
qualifiers?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
requireIntroduction?: Maybe<Scalars["Boolean"]["output"]>;
Expand Down Expand Up @@ -4334,7 +4347,6 @@ export type ReservationUnitUpdateMutationPayload = {
serviceSpecificTerms?: Maybe<Scalars["String"]["output"]>;
services?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
spaces?: Maybe<Array<Maybe<Scalars["Int"]["output"]>>>;
state?: Maybe<Scalars["String"]["output"]>;
surfaceArea?: Maybe<Scalars["Int"]["output"]>;
termsOfUse?: Maybe<Scalars["String"]["output"]>;
termsOfUseEn?: Maybe<Scalars["String"]["output"]>;
Expand Down Expand Up @@ -4994,6 +5006,9 @@ export type UnitNodeReservationunitSetArgs = {
onlyWithPermission?: InputMaybe<Scalars["Boolean"]["input"]>;
orderBy?: InputMaybe<Array<InputMaybe<ReservationUnitOrderingChoices>>>;
pk?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
publishingState?: InputMaybe<
Array<InputMaybe<ReservationUnitPublishingState>>
>;
purposes?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
qualifiers?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
rankGte?: InputMaybe<Scalars["Decimal"]["input"]>;
Expand All @@ -5004,10 +5019,11 @@ export type UnitNodeReservationunitSetArgs = {
reservableTimeEnd?: InputMaybe<Scalars["Time"]["input"]>;
reservableTimeStart?: InputMaybe<Scalars["Time"]["input"]>;
reservationKind?: InputMaybe<Scalars["String"]["input"]>;
reservationState?: InputMaybe<Array<InputMaybe<ReservationState>>>;
reservationState?: InputMaybe<
Array<InputMaybe<ReservationUnitReservationState>>
>;
reservationUnitType?: InputMaybe<Array<InputMaybe<Scalars["Int"]["input"]>>>;
showOnlyReservable?: InputMaybe<Scalars["Boolean"]["input"]>;
state?: InputMaybe<Array<InputMaybe<ReservationUnitState>>>;
surfaceAreaGte?: InputMaybe<Scalars["Decimal"]["input"]>;
surfaceAreaLte?: InputMaybe<Scalars["Decimal"]["input"]>;
textSearch?: InputMaybe<Scalars["String"]["input"]>;
Expand Down Expand Up @@ -6224,8 +6240,8 @@ export type ReservationUnitPageFieldsFragment = {
bufferTimeAfter: number;
reservationStartInterval: ReservationStartInterval;
canApplyFreeOfCharge: boolean;
state?: ReservationUnitState | null;
reservationState?: ReservationState | null;
publishingState?: ReservationUnitPublishingState | null;
reservationState?: ReservationUnitReservationState | null;
numActiveUserReservations?: number | null;
requireReservationHandling: boolean;
id: string;
Expand Down Expand Up @@ -6382,8 +6398,8 @@ export type ReservationUnitQuery = {
bufferTimeAfter: number;
reservationStartInterval: ReservationStartInterval;
canApplyFreeOfCharge: boolean;
state?: ReservationUnitState | null;
reservationState?: ReservationState | null;
publishingState?: ReservationUnitPublishingState | null;
reservationState?: ReservationUnitReservationState | null;
numActiveUserReservations?: number | null;
requireReservationHandling: boolean;
id: string;
Expand Down Expand Up @@ -6563,8 +6579,8 @@ export type ReservationUnitPageQuery = {
bufferTimeAfter: number;
reservationStartInterval: ReservationStartInterval;
canApplyFreeOfCharge: boolean;
state?: ReservationUnitState | null;
reservationState?: ReservationState | null;
publishingState?: ReservationUnitPublishingState | null;
reservationState?: ReservationUnitReservationState | null;
numActiveUserReservations?: number | null;
requireReservationHandling: boolean;
maxReservationDuration?: number | null;
Expand Down Expand Up @@ -7974,7 +7990,7 @@ export const ReservationUnitPageFieldsFragmentDoc = gql`
bufferTimeAfter
reservationStartInterval
canApplyFreeOfCharge
state
publishingState
reservationState
reservationUnitType {
...ReservationUnitTypeFields
Expand Down
40 changes: 24 additions & 16 deletions apps/ui/modules/__tests__/reservationUnit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
ReservationStateChoice,
PriceUnit,
PricingType,
ReservationUnitState,
ReservationUnitPublishingState,
type ReservationUnitNode,
Status,
Authentication,
ReservationKind,
ReservationStartInterval,
ReservationState,
ReservationUnitReservationState,
type PriceReservationUnitFragment,
} from "@gql/gql-types";
import {
Expand Down Expand Up @@ -387,38 +387,46 @@ describe("isReservationUnitPublished", () => {

test("with valid states", () => {
expect(
isReservationUnitPublished({ state: ReservationUnitState.Published })
isReservationUnitPublished({
publishingState: ReservationUnitPublishingState.Published,
})
).toBe(true);

expect(
isReservationUnitPublished({
state: ReservationUnitState.ScheduledHiding,
publishingState: ReservationUnitPublishingState.ScheduledHiding,
})
).toBe(true);
});

test("with invalid states", () => {
expect(
isReservationUnitPublished({ state: ReservationUnitState.Archived })
isReservationUnitPublished({
publishingState: ReservationUnitPublishingState.Archived,
})
).toBe(false);

expect(
isReservationUnitPublished({ state: ReservationUnitState.Draft })
isReservationUnitPublished({
publishingState: ReservationUnitPublishingState.Draft,
})
).toBe(false);

expect(
isReservationUnitPublished({ state: ReservationUnitState.Hidden })
isReservationUnitPublished({
publishingState: ReservationUnitPublishingState.Hidden,
})
).toBe(false);

expect(
isReservationUnitPublished({
state: ReservationUnitState.ScheduledPeriod,
publishingState: ReservationUnitPublishingState.ScheduledPeriod,
})
).toBe(false);

expect(
isReservationUnitPublished({
state: ReservationUnitState.ScheduledPublishing,
publishingState: ReservationUnitPublishingState.ScheduledPublishing,
})
).toBe(false);
});
Expand Down Expand Up @@ -1224,11 +1232,11 @@ describe("isReservationUnitReservable", () => {
function constructReservationUnitNode({
minReservationDuration = 3600,
maxReservationDuration = 3600,
reservationState = ReservationState.Reservable,
reservationState = ReservationUnitReservationState.Reservable,
}: {
minReservationDuration?: number;
maxReservationDuration?: number;
reservationState?: ReservationState;
reservationState?: ReservationUnitReservationState;
}) {
const date = new Date().toISOString().split("T")[0];
const reservationUnit: ReservationUnitNode = {
Expand Down Expand Up @@ -1297,7 +1305,7 @@ describe("isReservationUnitReservable", () => {

const [res2] = isReservationUnitReservable(
constructReservationUnitNode({
reservationState: ReservationState.ScheduledClosing,
reservationState: ReservationUnitReservationState.ScheduledClosing,
})
);
expect(res2).toBe(true);
Expand All @@ -1307,25 +1315,25 @@ describe("isReservationUnitReservable", () => {
const [res1] = isReservationUnitReservable({
...constructReservationUnitNode({}),
reservableTimeSpans: undefined,
reservationState: ReservationState.ReservationClosed,
reservationState: ReservationUnitReservationState.ReservationClosed,
});
expect(res1).toBe(false);

const [res2] = isReservationUnitReservable({
...constructReservationUnitNode({}),
reservationState: ReservationState.ReservationClosed,
reservationState: ReservationUnitReservationState.ReservationClosed,
});
expect(res2).toBe(false);

const [res5] = isReservationUnitReservable({
...constructReservationUnitNode({}),
reservationState: ReservationState.ScheduledReservation,
reservationState: ReservationUnitReservationState.ScheduledReservation,
});
expect(res5).toBe(false);

const [res6] = isReservationUnitReservable({
...constructReservationUnitNode({}),
reservationState: ReservationState.ScheduledPeriod,
reservationState: ReservationUnitReservationState.ScheduledPeriod,
});
expect(res6).toBe(false);
});
Expand Down
Loading