Skip to content
Open
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
160 changes: 157 additions & 3 deletions src/actions/__tests__/speaker-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import {
deleteRequest,
putRequest
putRequest,
getRequest
} from "openstack-uicore-foundation/lib/utils/actions";
import { removeAttachedPicture, saveSpeaker } from "../speaker-actions";
import {
removeAttachedPicture,
saveSpeaker,
getSpeakersBySummit,
sendSpeakerEmails
} from "../speaker-actions";
import * as methods from "../../utils/methods";

jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({
__esModule: true,
...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"),
deleteRequest: jest.fn(),
putRequest: jest.fn()
putRequest: jest.fn(),
getRequest: jest.fn()
}));

const SPEAKER_ID = 42;
Expand Down Expand Up @@ -144,3 +151,150 @@ describe("saveSpeaker", () => {
expect(settled).toBe(true);
});
});

describe("getSpeakersBySummit - published filter", () => {
const mockStore = configureStore([thunk]);
const SUMMIT_ID = 1;
let capturedRequests;

const stateWithSummit = {
currentSummitState: {
currentSummit: { id: SUMMIT_ID, name: "Test Summit" }
}
};

beforeEach(() => {
jest.clearAllMocks();
window.API_BASE_URL = "https://api.test";
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
capturedRequests = [];
getRequest.mockImplementation(
(_requestAction, receiveAction, url) => (params) => (dispatch) => {
capturedRequests.push({ url, params });
dispatch(receiveAction({ response: {} }));
return Promise.resolve({ response: {} });
}
);
});

afterEach(() => {
jest.restoreAllMocks();
delete window.API_BASE_URL;
});

const listRequestFor = () =>
capturedRequests.find((r) => r.url.endsWith("/speakers"));
const countRequestFor = () =>
capturedRequests.find((r) => r.url.endsWith("/speakers/all/events/count"));

it.each([
["published", "true"],
["not_published", "false"]
])(
"maps the '%s' filter to has_published_presentations==%s on both the list and count request",
async (selectionValue, expectedFlag) => {
const store = mockStore(stateWithSummit);

await store.dispatch(
getSpeakersBySummit(null, 1, 10, "full_name", 1, {
selectionStatusFilter: [selectionValue]
})
);

const expected = `has_published_presentations==${expectedFlag}`;
expect(listRequestFor().params["filter[]"]).toContain(expected);
expect(countRequestFor().params["filter[]"]).toContain(expected);
}
);

it("does not regress the existing only_accepted combination", async () => {
const store = mockStore(stateWithSummit);

await store.dispatch(
getSpeakersBySummit(null, 1, 10, "full_name", 1, {
selectionStatusFilter: ["only_accepted"]
})
);

const filter = listRequestFor().params["filter[]"];
expect(filter).toEqual(
expect.arrayContaining([
"has_rejected_presentations==false",
"has_accepted_presentations==true",
"has_alternate_presentations==false"
])
);
expect(filter.join(",")).not.toContain("has_published_presentations");
});
});

describe("sendSpeakerEmails - published filter", () => {
const mockStore = configureStore([thunk]);
const SUMMIT_ID = 1;
let capturedRequests;

const baseState = {
currentSummitState: {
currentSummit: { id: SUMMIT_ID, name: "Test Summit" }
},
currentSummitSpeakersListState: {
selectedAll: true,
selectedItems: [],
excludedItems: [],
currentFlowEvent: "SPEAKER_FLOW_EVENT"
}
};

beforeEach(() => {
jest.clearAllMocks();
window.API_BASE_URL = "https://api.test";
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
capturedRequests = [];
putRequest.mockImplementation(
(_requestAction, receiveAction, url, payload) =>
(params) =>
(dispatch) => {
capturedRequests.push({ url, params, payload });
dispatch(receiveAction({ response: {} }));
return Promise.resolve({ response: {} });
}
);
});

afterEach(() => {
jest.restoreAllMocks();
delete window.API_BASE_URL;
});

it("forwards the selected Published/Not Published filter unchanged into the bulk-email request", async () => {
const store = mockStore(baseState);

await store.dispatch(
sendSpeakerEmails(null, { selectionStatusFilter: ["published"] })
);

expect(capturedRequests[0].params["filter[]"]).toContain(
"has_published_presentations==true"
);
});

it("forwards the Published filter through original_filter when specific speakers are selected", async () => {
const store = mockStore({
...baseState,
currentSummitSpeakersListState: {
selectedAll: false,
selectedItems: [101, 202],
excludedItems: [],
currentFlowEvent: "SPEAKER_FLOW_EVENT"
}
});

await store.dispatch(
sendSpeakerEmails(null, { selectionStatusFilter: ["published"] })
);

expect(capturedRequests[0].payload.original_filter).toContain(
"has_published_presentations==true"
);
});
});
170 changes: 170 additions & 0 deletions src/actions/__tests__/submitter-actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* @jest-environment jsdom
*/
import configureStore from "redux-mock-store";
import thunk from "redux-thunk";
import {
getRequest,
putRequest
} from "openstack-uicore-foundation/lib/utils/actions";
import {
getSubmittersBySummit,
sendSubmitterEmails
} from "../submitter-actions";
import * as methods from "../../utils/methods";

jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({
__esModule: true,
...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"),
getRequest: jest.fn(),
putRequest: jest.fn()
}));

describe("getSubmittersBySummit - published filter", () => {
const mockStore = configureStore([thunk]);
const SUMMIT_ID = 1;
let capturedRequests;

const stateWithSummit = {
currentSummitState: {
currentSummit: { id: SUMMIT_ID, name: "Test Summit" }
}
};

beforeEach(() => {
jest.clearAllMocks();
window.API_BASE_URL = "https://api.test";
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
capturedRequests = [];
getRequest.mockImplementation(
(_requestAction, receiveAction, url) => (params) => (dispatch) => {
capturedRequests.push({ url, params });
dispatch(receiveAction({ response: {} }));
return Promise.resolve({ response: {} });
}
);
});

afterEach(() => {
jest.restoreAllMocks();
delete window.API_BASE_URL;
});

const listRequestFor = () =>
capturedRequests.find((r) => r.url.endsWith("/submitters"));
const countRequestFor = () =>
capturedRequests.find((r) =>
r.url.endsWith("/submitters/all/events/count")
);

it.each([
["published", "true"],
["not_published", "false"]
])(
"maps the '%s' filter to has_published_presentations==%s on both the list and count request",
async (selectionValue, expectedFlag) => {
const store = mockStore(stateWithSummit);

await store.dispatch(
getSubmittersBySummit(null, 1, 10, "full_name", 1, {
selectionStatusFilter: [selectionValue]
})
);

const expected = `has_published_presentations==${expectedFlag}`;
expect(listRequestFor().params["filter[]"]).toContain(expected);
expect(countRequestFor().params["filter[]"]).toContain(expected);
}
);

it("does not regress the existing only_accepted combination", async () => {
const store = mockStore(stateWithSummit);

await store.dispatch(
getSubmittersBySummit(null, 1, 10, "full_name", 1, {
selectionStatusFilter: ["only_accepted"]
})
);

const filter = listRequestFor().params["filter[]"];
expect(filter).toEqual(
expect.arrayContaining([
"has_rejected_presentations==false",
"has_accepted_presentations==true",
"has_alternate_presentations==false"
])
);
expect(filter.join(",")).not.toContain("has_published_presentations");
});
});

describe("sendSubmitterEmails - published filter", () => {
const mockStore = configureStore([thunk]);
const SUMMIT_ID = 1;
let capturedRequests;

const baseState = {
currentSummitState: {
currentSummit: { id: SUMMIT_ID, name: "Test Summit" }
},
currentSummitSubmittersListState: {
selectedAll: true,
selectedItems: [],
excludedItems: [],
currentFlowEvent: "SUBMITTER_FLOW_EVENT"
}
};

beforeEach(() => {
jest.clearAllMocks();
window.API_BASE_URL = "https://api.test";
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
capturedRequests = [];
putRequest.mockImplementation(
(_requestAction, receiveAction, url, payload) =>
(params) =>
(dispatch) => {
capturedRequests.push({ url, params, payload });
dispatch(receiveAction({ response: {} }));
return Promise.resolve({ response: {} });
}
);
});

afterEach(() => {
jest.restoreAllMocks();
delete window.API_BASE_URL;
});

it("forwards the selected Published/Not Published filter unchanged into the bulk-email request", async () => {
const store = mockStore(baseState);

await store.dispatch(
sendSubmitterEmails(null, { selectionStatusFilter: ["published"] })
);

expect(capturedRequests[0].params["filter[]"]).toContain(
"has_published_presentations==true"
);
});

it("forwards the Published filter through original_filter when specific submitters are selected", async () => {
const store = mockStore({
...baseState,
currentSummitSubmittersListState: {
selectedAll: false,
selectedItems: [101, 202],
excludedItems: [],
currentFlowEvent: "SUBMITTER_FLOW_EVENT"
}
});

await store.dispatch(
sendSubmitterEmails(null, { selectionStatusFilter: ["published"] })
);

expect(capturedRequests[0].payload.original_filter).toContain(
"has_published_presentations==true"
);
});
});
4 changes: 4 additions & 0 deletions src/actions/speaker-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,10 @@ const parseFilters = (filters) => {
filter.push("has_rejected_presentations==true");
filter.push("has_accepted_presentations==false");
filter.push("has_alternate_presentations==true");
} else if (filters.selectionStatusFilter.includes("published")) {
filter.push("has_published_presentations==true");
} else if (filters.selectionStatusFilter.includes("not_published")) {
filter.push("has_published_presentations==false");
} else {
filter.push(
filters.selectionStatusFilter.reduce(
Expand Down
4 changes: 4 additions & 0 deletions src/actions/submitter-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ const parseFilters = (filters) => {
filter.push("has_rejected_presentations==true");
filter.push("has_accepted_presentations==false");
filter.push("has_alternate_presentations==true");
} else if (filters.selectionStatusFilter.includes("published")) {
filter.push("has_published_presentations==true");
} else if (filters.selectionStatusFilter.includes("not_published")) {
filter.push("has_published_presentations==false");
} else {
filter.push(
filters.selectionStatusFilter.reduce(
Expand Down
Loading
Loading