diff --git a/ui/src/services/EmailService.ts b/ui/src/services/EmailService.ts
index 9ac99b22..204ec896 100644
--- a/ui/src/services/EmailService.ts
+++ b/ui/src/services/EmailService.ts
@@ -22,8 +22,28 @@ export type EmailResult = {
text: string
}
+/**
+ * Sends feedback to Groupings API to send email.
+ *
+ * @param feedback - the feedback
+ *
+ * @returns The EmailResult
+ */
export const sendFeedback = async (feedback: Feedback): Promise => {
const currentUser = await getCurrentUser();
const endpoint = `${baseUrl}/email/send/feedback`;
- return postRequest(endpoint, currentUser.uid, feedback);
+ return postRequest(endpoint, currentUser.uid, feedback);
+}
+
+/**
+ * Sends feedback to Groupings API to send stack trace email.
+ *
+ * @param stackTrace - the stack trace
+ *
+ * @returns The EmailResult
+ */
+export const sendStackTrace = async (stackTrace: string): Promise => {
+ const currentUser = await getCurrentUser();
+ const endpoint = `${baseUrl}/email/send/stack-trace`;
+ return postRequest(endpoint, currentUser.uid, stackTrace, 'text/plain');
}
diff --git a/ui/src/services/FetchService.ts b/ui/src/services/FetchService.ts
index fd2cfe93..4b2c73dd 100644
--- a/ui/src/services/FetchService.ts
+++ b/ui/src/services/FetchService.ts
@@ -2,10 +2,23 @@
import { ApiError } from '../groupings/GroupingsApiResults';
import { getCurrentUser } from '@/access/AuthenticationService';
+import { sendStackTrace } from './EmailService';
const maxRetries = 3;
const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;
+enum HTTPMethod {
+ GET = 'GET',
+ POST = 'POST',
+ PUT = 'PUT',
+ DELETE = 'DELETE'
+}
+
+enum Status {
+ COMPLETED = 'COMPLETED',
+ IN_PROGRESS = 'IN_PROGRESS'
+}
+
/**
* Sleep/wait for the specified milliseconds.
*
@@ -24,10 +37,10 @@ const delay = async (ms = 5000) => new Promise((res) => setTimeout(res, ms));
*/
const poll = async (jobId: number): Promise => {
const currentUser = await getCurrentUser();
- return fetch(`${baseUrl}/jobs/${jobId}`, { headers: { 'current_user': currentUser.uid } })
- .then(res => res.json())
+ return await fetch(`${baseUrl}/jobs/${jobId}`, { headers: { 'current_user': currentUser.uid } })
+ .then(res => handleFetch(res, HTTPMethod.GET))
.then(async res => {
- if (res.status === 'COMPLETED') {
+ if (res.status === Status.COMPLETED) {
return res.result;
}
await delay();
@@ -49,7 +62,7 @@ export const getRequest = async (
currentUserKey: string = ''
): Promise =>
await fetch(endpoint, { headers: { 'current_user': currentUserKey } })
- .then(res => res.json())
+ .then(res => handleFetch(res, HTTPMethod.GET))
.catch(err => err);
/**
@@ -65,12 +78,17 @@ export const postRequest = async (
endpoint: string,
currentUserKey: string,
body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
await fetch(endpoint, {
- method: 'POST',
- headers: { 'current_user': currentUserKey },
- body: JSON.stringify(body)})
- .then(res => res.json())
+ method: HTTPMethod.POST,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.POST))
.catch(err => err);
/**
@@ -85,10 +103,18 @@ export const postRequest = async (
export const postRequestAsync = async (
endpoint: string,
currentUserKey: string,
- body: string | string[]
+ body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
- await fetch(endpoint, { method: 'POST', headers: { 'current_user': currentUserKey }, body: JSON.stringify(body) })
- .then(res => res.json())
+ await fetch(endpoint, {
+ method: HTTPMethod.POST,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.POST))
.then(res => poll(res))
.catch(err => err);
@@ -104,16 +130,24 @@ export const postRequestAsync = async (
export const postRequestRetry = async (
endpoint: string,
currentUserKey: string,
- body: string | string[],
+ body?: object | string | string[],
+ contentType = 'application/json',
retries: number = maxRetries
): Promise =>
- await fetch(endpoint, { method: 'POST', headers: { 'current_user': currentUserKey }, body: JSON.stringify(body) })
+ await fetch(endpoint, {
+ method: HTTPMethod.POST,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
.then(async res => {
if (res.status === 500 && retries > 0) {
await delay(2000 * Math.log(maxRetries / retries));
- return postRequestRetry(endpoint, currentUserKey, body, retries - 1);
+ return postRequestRetry(endpoint, currentUserKey, body, contentType, retries - 1);
}
- return res.json();
+ return handleFetch(res, HTTPMethod.POST);
})
.catch(err => err);
@@ -130,13 +164,18 @@ export const postRequestRetry = async (
export const putRequest = async (
endpoint: string,
currentUserKey: string,
- body?: object | string | string[]
+ body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
await fetch(endpoint, {
- method: 'PUT',
- headers: { 'current_user': currentUserKey },
- body: JSON.stringify(body) })
- .then(res => res.json())
+ method: HTTPMethod.PUT,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.PUT))
.catch(err => err);
/**
@@ -151,10 +190,18 @@ export const putRequest = async (
export const putRequestAsync = async (
endpoint: string,
currentUserKey: string,
- body: string | string[]
+ body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
- await fetch(endpoint, { method: 'PUT', headers: { 'current_user': currentUserKey }, body: JSON.stringify(body) })
- .then(res => res.json())
+ await fetch(endpoint, {
+ method: HTTPMethod.PUT,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.PUT))
.then(res => poll(res))
.catch(err => err);
@@ -170,11 +217,18 @@ export const putRequestAsync = async (
export const deleteRequest = async (
endpoint: string,
currentUserKey: string,
- body?: object | string | string[]
+ body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
- await fetch(endpoint, { method: 'DELETE', headers: { 'current_user': currentUserKey }, body: JSON.stringify(body) })
- .then(res => res.json())
- .then(res => (res))
+ await fetch(endpoint, {
+ method: HTTPMethod.DELETE,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.DELETE))
.catch(err => err);
/**
@@ -189,12 +243,49 @@ export const deleteRequest = async (
export const deleteRequestAsync = async (
endpoint: string,
currentUserKey: string,
- body?: object | string | string[]
+ body?: object | string | string[],
+ contentType = 'application/json'
): Promise =>
await fetch(endpoint, {
- method: 'DELETE',
- headers: { 'current_user': currentUserKey },
- body: JSON.stringify(body) })
- .then(res => res.json())
+ method: HTTPMethod.DELETE,
+ headers: {
+ 'current_user': currentUserKey,
+ 'Content-Type': contentType
+ },
+ body: stringifyBody(body)
+ })
+ .then(res => handleFetch(res, HTTPMethod.DELETE))
.then(res => poll(res))
.catch(err => err);
+
+/**
+ * Helper function for the .then clause of a fetch promise.
+ * Sends an email stack trace if an error is thrown.
+ *
+ * @param res - the response
+ * @param httpMethod - the HTTPMethod
+ *
+ * @returns The res.json()
+ */
+const handleFetch = (res: Response, httpMethod: HTTPMethod) => {
+ if (!res.ok) {
+ const error = Error(`${res.status} error from ${httpMethod} ${res.url}`);
+ sendStackTrace(error.stack as string);
+ }
+ return res.json();
+}
+
+/**
+ * Helper function to JSON.stringify the body of a request or keep as a string
+ * if the passed body is already a string.
+ *
+ * @param body - the body of a request
+ *
+ * @returns The stringified body
+ */
+const stringifyBody = (body: object | string | string[] | undefined) => {
+ if (typeof body === 'string') {
+ return body
+ }
+ return JSON.stringify(body)
+};
diff --git a/ui/tests/app/about/About.test.tsx b/ui/tests/app/about/About.test.tsx
index 647c83dd..2d6a1af5 100644
--- a/ui/tests/app/about/About.test.tsx
+++ b/ui/tests/app/about/About.test.tsx
@@ -1,4 +1,4 @@
-import {render, screen} from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import About from '@/app/about/page';
describe('About', () => {
@@ -14,8 +14,7 @@ describe('About', () => {
expect(screen.getByText('GENERAL INFO')).toBeInTheDocument();
expect(screen.getByRole('link', {name: 'A request form is available'}))
- .toHaveAttribute('href', 'https://uhawaii.atlassian.net/wiki/spaces/UHIAM/pages/13402308/' +
- ' UH+Groupings+Request+Form');
+ .toHaveAttribute('href', 'https://uhawaii.atlassian.net/wiki/spaces/UHIAM/pages/13402308/UH+Groupings+Request+Form');
expect(screen.getByRole('link', {name: 'General information about groupings is available'}))
.toHaveAttribute('href', 'https://uhawaii.atlassian.net/wiki/spaces/UHIAM/pages/13403213/UH+Groupings');
diff --git a/ui/tests/services/EmailService.test.ts b/ui/tests/services/EmailService.test.ts
index a59183b8..50d2662c 100644
--- a/ui/tests/services/EmailService.test.ts
+++ b/ui/tests/services/EmailService.test.ts
@@ -1,5 +1,5 @@
import User from '@/access/User';
-import { Feedback, sendFeedback } from '@/services/EmailService';
+import { Feedback, sendFeedback, sendStackTrace } from '@/services/EmailService';
import * as AuthenticationService from '@/access/AuthenticationService';
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string;
@@ -10,7 +10,6 @@ jest.mock('@/access/AuthenticationService');
describe('EmailService', () => {
const currentUser = testUser;
- const headers = { 'current_user': currentUser.uid };
beforeAll(() => {
jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(testUser);
@@ -29,10 +28,30 @@ describe('EmailService', () => {
await sendFeedback(feedback);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/email/send/feedback`, {
body: JSON.stringify(feedback),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
-
});
+
+ describe('sendStackTrace', () => {
+
+ const stackTrace = 'stackTrace';
+
+ it('should make a POST request at the correct endpoint', async () => {
+ await sendStackTrace(stackTrace);
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/email/send/stack-trace`, {
+ body: stackTrace,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'text/plain'
+ },
+ method: 'POST'
+ });
+ });
+ });
+
});
diff --git a/ui/tests/services/GroupingsApiService.test.ts b/ui/tests/services/GroupingsApiService.test.ts
index 58004c8f..24e28875 100644
--- a/ui/tests/services/GroupingsApiService.test.ts
+++ b/ui/tests/services/GroupingsApiService.test.ts
@@ -42,11 +42,11 @@ const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string;
const testUser: User = JSON.parse(process.env.TEST_USER_A as string);
jest.mock('@/access/AuthenticationService');
+jest.mock('@/services/EmailService');
describe('GroupingsService', () => {
const currentUser = testUser;
- const headers = { 'current_user': currentUser.uid };
const uhIdentifier = 'testiwta';
const uhIdentifiers = ['testiwta', 'testiwtb'];
@@ -117,7 +117,10 @@ describe('GroupingsService', () => {
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/group?`
+ `page=${page}&size=${size}&sortString=${sortString}&isAscending=${isAscending}`, {
body: JSON.stringify(groupPaths),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -167,7 +170,9 @@ describe('GroupingsService', () => {
describe('groupingDescription', () => {
it('should make a GET request at the correct endpoint', async () => {
await groupingDescription(groupingPath);
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/description`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/description`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -184,8 +189,9 @@ describe('GroupingsService', () => {
describe('groupingSyncDest', () => {
it('should make a GET request at the correct endpoint', async () => {
await groupingSyncDest(groupingPath);
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/groupings-sync-destinations`,
- { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/groupings-sync-destinations`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -202,8 +208,9 @@ describe('GroupingsService', () => {
describe('groupingOptAttributes', () => {
it('should make a GET request at the correct endpoint', async () => {
await groupingOptAttributes(groupingPath);
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/opt-attributes`,
- { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/opt-attributes`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -223,8 +230,11 @@ describe('GroupingsService', () => {
it('should make a POST request at the correct endpoint', async () => {
await updateDescription(description, groupingPath);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/description`, {
- body: JSON.stringify(description),
- headers,
+ body: description,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -243,7 +253,9 @@ describe('GroupingsService', () => {
describe('groupingAdmins', () => {
it('should make a GET request at the correct endpoint', async () => {
await groupingAdmins();
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/grouping-admins`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/grouping-admins`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -260,7 +272,9 @@ describe('GroupingsService', () => {
describe('getAllGroupings', () => {
it('should make a GET request at the correct endpoint', async () => {
await getAllGroupings();
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/all-groupings`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/all-groupings`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -280,7 +294,10 @@ describe('GroupingsService', () => {
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/include-members`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
});
});
@@ -310,7 +327,10 @@ describe('GroupingsService', () => {
expect(fetch).toHaveBeenCalledWith(
`${baseUrl}/groupings/${groupingPath}/include-members/async`,{
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
});
});
@@ -347,7 +367,10 @@ describe('GroupingsService', () => {
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/exclude-members`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
});
});
@@ -377,7 +400,10 @@ describe('GroupingsService', () => {
expect(fetch).toHaveBeenCalledWith(
`${baseUrl}/groupings/${groupingPath}/exclude-members/async`,{
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
});
});
@@ -412,7 +438,10 @@ describe('GroupingsService', () => {
it('should make a POST request at the correct endpoint', async () => {
await addOwners(uhIdentifiers, groupingPath);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/owners/${uhIdentifiers}`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -432,7 +461,10 @@ describe('GroupingsService', () => {
it('should make a POST request at the correct endpoint', async () => {
await addAdmin(uhIdentifier);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/admins/${uhIdentifier}`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -452,7 +484,10 @@ describe('GroupingsService', () => {
it('should make a DELETE request at the correct endpoint', async () => {
await removeFromGroups(uhIdentifier, groupPaths);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/admins/${groupPaths}/${uhIdentifier}`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -473,7 +508,10 @@ describe('GroupingsService', () => {
await removeIncludeMembers(uhIdentifiers, groupingPath);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/include-members`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -494,7 +532,10 @@ describe('GroupingsService', () => {
await removeExcludeMembers(uhIdentifiers, groupingPath);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/exclude-members`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -514,7 +555,10 @@ describe('GroupingsService', () => {
it('should make a DELETE request at the correct endpoint', async () => {
await removeOwners(uhIdentifiers, groupingPath);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/owners/${uhIdentifiers}`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -534,7 +578,10 @@ describe('GroupingsService', () => {
it('should make a DELETE request at the correct endpoint', async () => {
await removeAdmin(uhIdentifier);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/admins/${uhIdentifier}`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -555,7 +602,10 @@ describe('GroupingsService', () => {
await memberAttributeResults(uhIdentifiers);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -584,7 +634,10 @@ describe('GroupingsService', () => {
await memberAttributeResultsAsync(uhIdentifiers);
expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/async`, {
body: JSON.stringify(uhIdentifiers),
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'POST'
});
});
@@ -609,7 +662,7 @@ describe('GroupingsService', () => {
fetchMock
.mockResponseOnce(JSON.stringify(0))
.mockRejectOnce(() => Promise.reject(mockError));
- res = addExcludeMembersAsync(uhIdentifiers, groupingPath);
+ res = memberAttributeResultsAsync(uhIdentifiers);
await jest.advanceTimersByTimeAsync(5000);
expect(await res).toEqual(mockError);
});
@@ -620,7 +673,10 @@ describe('GroupingsService', () => {
await optIn(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/include-members/${currentUser.uid}/self`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
});
});
@@ -641,7 +697,10 @@ describe('GroupingsService', () => {
await optOut(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/exclude-members/${currentUser.uid}/self`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'PUT'
})
});
@@ -660,7 +719,9 @@ describe('GroupingsService', () => {
describe('membershipResults', () => {
it('should make a GET request at the correct endpoint', async () => {
await membershipResults();
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${currentUser.uid}/memberships`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${currentUser.uid}/memberships`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -677,7 +738,9 @@ describe('GroupingsService', () => {
describe('managePersonResults', () => {
it('should make a GET request at the correct endpoint', async () => {
await managePersonResults(uhIdentifier);
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${uhIdentifier}/groupings`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${uhIdentifier}/groupings`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -694,7 +757,9 @@ describe('GroupingsService', () => {
describe('getNumberOfMemberships', () => {
it('should make a GET request at the correct endpoint', async () => {
await getNumberOfMemberships();
- expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${currentUser.uid}/memberships/count`, { headers });
+ expect(fetch).toHaveBeenCalledWith(`${baseUrl}/members/${currentUser.uid}/memberships/count`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -712,7 +777,9 @@ describe('GroupingsService', () => {
it('should make a GET request at the correct endpoint', async () => {
await optInGroupingPaths();
expect(fetch)
- .toHaveBeenCalledWith(`${baseUrl}/groupings/members/${currentUser.uid}/opt-in-groups`, { headers });
+ .toHaveBeenCalledWith(`${baseUrl}/groupings/members/${currentUser.uid}/opt-in-groups`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -731,7 +798,10 @@ describe('GroupingsService', () => {
await resetIncludeGroup(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/include`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -760,7 +830,10 @@ describe('GroupingsService', () => {
await resetIncludeGroupAsync(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/include/async`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -796,7 +869,10 @@ describe('GroupingsService', () => {
await resetExcludeGroup(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/exclude`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -825,7 +901,10 @@ describe('GroupingsService', () => {
await resetExcludeGroupAsync(groupingPath);
expect(fetch)
.toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/exclude/async`, {
- headers,
+ headers: {
+ 'current_user': currentUser.uid,
+ 'Content-Type': 'application/json'
+ },
method: 'DELETE'
});
});
@@ -860,7 +939,9 @@ describe('GroupingsService', () => {
it('should make a GET request at the correct endpoint', async () => {
await groupingOwners(groupingPath);
expect(fetch)
- .toHaveBeenCalledWith(`${baseUrl}/grouping/${groupingPath}/owners`, { headers });
+ .toHaveBeenCalledWith(`${baseUrl}/grouping/${groupingPath}/owners`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -878,7 +959,9 @@ describe('GroupingsService', () => {
it('should make a GET request at the correct endpoint', async () => {
await ownerGroupings();
expect(fetch)
- .toHaveBeenCalledWith(`${baseUrl}/owners/${currentUser.uid}/groupings`, { headers });
+ .toHaveBeenCalledWith(`${baseUrl}/owners/${currentUser.uid}/groupings`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -896,7 +979,9 @@ describe('GroupingsService', () => {
it('should make a GET request at the correct endpoint', async () => {
await getNumberOfGroupings();
expect(fetch)
- .toHaveBeenCalledWith(`${baseUrl}/owners/${currentUser.uid}/groupings/count`, { headers });
+ .toHaveBeenCalledWith(`${baseUrl}/owners/${currentUser.uid}/groupings/count`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {
@@ -914,7 +999,9 @@ describe('GroupingsService', () => {
it('should make a GET request at the correct endpoint', async () => {
await isSoleOwner(uhIdentifier, groupingPath);
expect(fetch)
- .toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/owners/${uhIdentifier}`, { headers });
+ .toHaveBeenCalledWith(`${baseUrl}/groupings/${groupingPath}/owners/${uhIdentifier}`, {
+ headers: { 'current_user': currentUser.uid }
+ });
});
it('should handle the successful response', async () => {