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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@iconscout/react-unicons": "^1.1.6",
"@internxt/css-config": "1.1.0",
"@internxt/lib": "1.4.1",
"@internxt/sdk": "=1.12.4",
"@internxt/sdk": "=1.12.0",
"@internxt/ui": "0.1.1",
"@phosphor-icons/react": "^2.1.7",
"@popperjs/core": "^2.11.6",
Expand Down
34 changes: 0 additions & 34 deletions src/app/core/factory/sdk/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import { STORAGE_KEYS } from 'services/storage-keys';
import { Share, Users } from '@internxt/sdk/dist/drive';
import packageJson from '../../../../../package.json';
import { Auth } from '@internxt/sdk/dist/auth';
import { Location } from '@internxt/sdk';

const MOCKED_NEW_API = 'https://api.internxt.com';
const MOCKED_PAYMENTS = 'https://payments.internxt.com';
const MOCKED_LOCATION = 'https://location.internxt.com';

vi.mock('@internxt/sdk/dist/drive', () => ({
Users: {
Expand All @@ -28,18 +26,11 @@ vi.mock('@internxt/sdk/dist/auth', () => ({
},
}));

vi.mock('@internxt/sdk', () => ({
Location: {
client: vi.fn(),
},
}));

vi.mock('services/env.service', () => ({
default: {
getVariable: vi.fn((key: string) => {
if (key === 'newApi') return MOCKED_NEW_API;
if (key === 'payments') return MOCKED_PAYMENTS;
if (key === 'location') return MOCKED_LOCATION;
return '';
}),
},
Expand Down Expand Up @@ -347,30 +338,5 @@ describe('SdkFactory', () => {
);
});
});

describe('Creating the location client', () => {
test('When the Location client is created, then it uses the location API URL and default app details', () => {
const mockToken = 'test-token';
const mockWorkspace = Workspace.Individuals;

vi.spyOn(mockLocalStorage, 'getWorkspace').mockReturnValue(mockWorkspace);
vi.spyOn(mockLocalStorage, 'get').mockImplementation((key: string) => {
if (key === 'xNewToken') return mockToken;
return null;
});

const instance = SdkFactory.getNewApiInstance();
instance.createLocationClient();

expect(Location.client).toHaveBeenCalledWith(
MOCKED_LOCATION,
{
clientName: packageJson.name,
clientVersion: packageJson.version,
},
expect.any(Object),
);
});
});
});
});
8 changes: 0 additions & 8 deletions src/app/core/factory/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Workspace } from '../../types';
import { Checkout } from '@internxt/sdk/dist/payments';
import envService from 'services/env.service';
import { STORAGE_KEYS } from 'services/storage-keys';
import { Location } from '@internxt/sdk';

export class SdkFactory {
private static sdk: {
Expand Down Expand Up @@ -114,13 +113,6 @@ export class SdkFactory {
return Backups.client(apiUrl, appDetails, apiSecurity);
}

public createLocationClient(): Location {
const apiUrl = envService.getVariable('location');
const appDetails = SdkFactory.getAppDetails();
const apiSecurity = this.getNewApiSecurity();
return Location.client(apiUrl, appDetails, apiSecurity);
}

/** Helpers **/

private getNewApiSecurity(unauthorizedCallback?: () => void): ApiSecurity {
Expand Down
33 changes: 19 additions & 14 deletions src/utils/userLocation.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
// tests/userLocation.test.ts
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
import * as sdk from '@internxt/sdk';
import { userLocation } from './userLocation';
import { SdkFactory } from 'app/core/factory/sdk';

vi.mock('app/core/factory/sdk', () => ({
SdkFactory: {
getNewApiInstance: vi.fn(),
vi.mock('@internxt/sdk', async () => {
const actual = await vi.importActual<typeof import('@internxt/sdk')>('@internxt/sdk');
return {
...actual,
getUserLocation: vi.fn(),
};
});

vi.mock('../../config', () => ({
envConfig: {
api: {
location: 'https://mocked-location-api.com',
},
},
}));

Expand All @@ -14,21 +25,15 @@ describe('User location function', () => {
location: 'ES',
};

const mockGetUserLocation = vi.fn();
const mockCreateLocationClient = vi.fn();

beforeEach(() => {
vi.clearAllMocks();
mockGetUserLocation.mockResolvedValue(mockedLocation);
mockCreateLocationClient.mockReturnValue({ getUserLocation: mockGetUserLocation });
vi.mocked(SdkFactory.getNewApiInstance).mockReturnValue({
createLocationClient: mockCreateLocationClient,
} as unknown as SdkFactory);
vi.resetModules();
(sdk.getUserLocation as Mock).mockResolvedValue(mockedLocation);
});

it('When the user location is requested, then the IP and country are returned', async () => {
const result = await userLocation();

expect(result).toStrictEqual(mockedLocation);
expect(result).toEqual(mockedLocation);
});
});
7 changes: 3 additions & 4 deletions src/utils/userLocation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { UserLocation } from '@internxt/sdk';
import { SdkFactory } from 'app/core/factory/sdk';
import { getUserLocation, UserLocation } from '@internxt/sdk';
import envService from 'services/env.service';

export const userLocation = (): Promise<UserLocation> => {
const client = SdkFactory.getNewApiInstance().createLocationClient();
return client.getUserLocation();
return getUserLocation(envService.getVariable('location'));
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1906,10 +1906,10 @@
version "1.0.2"
resolved "https://codeload.github.com/internxt/prettier-config/tar.gz/9fa74e9a2805e1538b50c3809324f1c9d0f3e4f9"

"@internxt/sdk@=1.12.4":
version "1.12.4"
resolved "https://registry.yarnpkg.com/@internxt/sdk/-/sdk-1.12.4.tgz#5874d5b2705919a27f4e621e8179443e5bbdc43f"
integrity sha512-amADmUpOubu2wnbGq+DZqgK03JCKJcLuijiigY29SwBSrdknTlAqAetQSpbl/RXnBpeqnTTZtYXMJPYB14qbHw==
"@internxt/sdk@=1.12.0":
version "1.12.0"
resolved "https://registry.yarnpkg.com/@internxt/sdk/-/sdk-1.12.0.tgz#cf9c2f0ca8864a688e4c161f470e171997bff7bb"
integrity sha512-QrjH2yJP7MjxAVvkOe6quqX7RYzC6e3M0XcXralJEFybDpimJBJbvRTPUe7+9XRQ6gHdmYi1u3ySDVoZyZpkug==
dependencies:
axios "1.13.2"
uuid "11.1.0"
Expand Down
Loading