Skip to content
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
23 changes: 0 additions & 23 deletions src/app/lib/uasApi/getAuthHeader.ts

This file was deleted.

17 changes: 17 additions & 0 deletions src/app/lib/uasApi/getAuthHeaders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getEnvConfig } from '../utilities/getEnvConfig';

const getAuthHeaders = (): HeadersInit => {
const apiKey = getEnvConfig().SIMORGH_UAS_PUBLIC_API_KEY;

if (!apiKey) {
throw new Error('Missing UAS public API key');
}

const headers: HeadersInit = {
'X-API-Key': apiKey,
};

return headers;
};

export default getAuthHeaders;
25 changes: 1 addition & 24 deletions src/app/lib/uasApi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ describe('uasApiRequest', () => {
expect.objectContaining({
method: 'GET',
headers: expect.objectContaining({
Authorization: 'Bearer mocked-token',
'X-Authentication-Provider': 'idv5',
'X-API-Key': 'mocked-api-key',
}),
}),
Expand All @@ -63,8 +61,6 @@ describe('uasApiRequest', () => {
expect.objectContaining({
method: 'POST',
headers: expect.objectContaining({
Authorization: 'Bearer mocked-token',
'X-Authentication-Provider': 'idv5',
'X-API-Key': 'mocked-api-key',
'Content-Type': 'application/json',
}),
Expand All @@ -91,8 +87,6 @@ describe('uasApiRequest', () => {
expect.objectContaining({
method: 'DELETE',
headers: expect.objectContaining({
Authorization: 'Bearer mocked-token',
'X-Authentication-Provider': 'idv5',
'X-API-Key': 'mocked-api-key',
}),
}),
Expand Down Expand Up @@ -121,23 +115,6 @@ describe('uasApiRequest', () => {
);
});

it('should throw an error when ckns_atkn cookie is missing', async () => {
// Mock the scenario where the ckns_atkn cookie is not in storage
(mockCookie.get as jest.Mock).mockReturnValue(undefined);
mockGetEnvConfig.mockReturnValue({
SIMORGH_UAS_PUBLIC_API_KEY: 'mocked-api-key',
} as ReturnType<typeof getEnvConfig>);

const activityType = 'favourites';

await expect(uasApiRequest('GET', activityType)).rejects.toThrow(
'Missing authentication for UAS request',
);

// Verify that fetch was never called since authentication failed
expect(global.fetch).not.toHaveBeenCalled();
});

it('should throw an error when API key is missing', async () => {
// Mock the scenario where the API key is not configured
(mockCookie.get as jest.Mock).mockReturnValue('mocked-token');
Expand All @@ -148,7 +125,7 @@ describe('uasApiRequest', () => {
const activityType = 'favourites';

await expect(uasApiRequest('GET', activityType)).rejects.toThrow(
'Missing authentication for UAS request',
'Missing UAS public API key',
);

// Verify that fetch was never called since authentication failed
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/uasApi/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isLive from '#app/lib/utilities/isLive';
import getAuthHeaders from './getAuthHeader';
import getAuthHeaders from './getAuthHeaders';
import { activityTypes } from './uasUtility';

export type UasMethod = 'POST' | 'DELETE' | 'GET';
Expand Down
Loading