Skip to content

Commit 0568f7b

Browse files
committed
Rename to getAuthHeaders
1 parent 79e7583 commit 0568f7b

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

dotcom-rendering/src/components/SlotBodyEnd/ReaderRevenueEpic.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
import { useEffect, useState } from 'react';
2121
import { submitComponentEvent } from '../../client/ophan/ophan';
2222
import {
23-
buildRequestHeaders,
23+
getAuthHeaders,
2424
hasCmpConsentForWeeklyArticleCount,
2525
hasOptedOutOfArticleCount,
2626
shouldHideSupportMessaging,
@@ -107,7 +107,7 @@ export const canShowReaderRevenueEpic = async (
107107
hideSupportMessagingForUser,
108108
});
109109

110-
const headers = await buildRequestHeaders();
110+
const headers = await getAuthHeaders();
111111

112112
const response: ModuleDataResponse<EpicProps> = await getEpic(
113113
contributionsServiceUrl,

dotcom-rendering/src/lib/contributions.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createOrRenewCookie } from '../client/userFeatures/cookies/cookieHelper
44
import { HIDE_SUPPORT_MESSAGING_COOKIE } from '../client/userFeatures/cookies/hideSupportMessaging';
55
import { USER_BENEFITS_EXPIRY_COOKIE } from '../client/userFeatures/cookies/userBenefitsExpiry';
66
import {
7-
buildRequestHeaders,
7+
getAuthHeaders,
88
getLastOneOffContributionTimestamp,
99
hasHideSupportMessagingCookie,
1010
isRecentOneOffContributor,
@@ -216,23 +216,23 @@ const getAuthStatus = getAuthStatus_ as jest.MockedFunction<
216216
typeof getAuthStatus_
217217
>;
218218

219-
describe('buildRequestHeaders', () => {
219+
describe('getAuthHeaders', () => {
220220
beforeEach(() => {
221221
jest.clearAllMocks();
222222
});
223223

224224
it('returns undefined when user has not consented to targeting', async () => {
225225
(onConsent as jest.Mock).mockResolvedValue({ canTarget: false });
226226

227-
const result = await buildRequestHeaders();
227+
const result = await getAuthHeaders();
228228

229229
expect(result).toBeUndefined();
230230
});
231231

232232
it('returns undefined when consent check fails', async () => {
233233
(onConsent as jest.Mock).mockRejectedValue(new Error('Consent error'));
234234

235-
const result = await buildRequestHeaders();
235+
const result = await getAuthHeaders();
236236

237237
expect(result).toBeUndefined();
238238
});
@@ -241,7 +241,7 @@ describe('buildRequestHeaders', () => {
241241
(onConsent as jest.Mock).mockResolvedValue({ canTarget: true });
242242
(getAuthStatus as jest.Mock).mockResolvedValue({ kind: 'SignedOut' });
243243

244-
const result = await buildRequestHeaders();
244+
const result = await getAuthHeaders();
245245

246246
expect(result).toBeUndefined();
247247
});
@@ -253,7 +253,7 @@ describe('buildRequestHeaders', () => {
253253
accessToken: { accessToken: 'token' },
254254
});
255255

256-
const result = await buildRequestHeaders();
256+
const result = await getAuthHeaders();
257257

258258
expect(result).toEqual({
259259
Authorization: 'Bearer token',

dotcom-rendering/src/lib/contributions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,8 @@ const hasCanTargetConsent = (): Promise<boolean> =>
232232
.then(({ canTarget }: ConsentState) => canTarget)
233233
.catch(() => false);
234234

235-
export const buildRequestHeaders = async (): Promise<
236-
HeadersInit | undefined
237-
> => {
238-
// If user has targeting consent and is signed in then we can send an Authorization header
235+
// Returns Auth headers only if user has targeting consent and is signed in
236+
export const getAuthHeaders = async (): Promise<HeadersInit | undefined> => {
239237
const hasConsented = await hasCanTargetConsent();
240238
if (hasConsented) {
241239
const authStatus = await getAuthStatus();

0 commit comments

Comments
 (0)