Skip to content

Commit

Permalink
Fix broken test mocking, switch to os.platform
Browse files Browse the repository at this point in the history
  • Loading branch information
FinalDoom committed Jan 2, 2024
1 parent db9640d commit 17ec3e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions server/services/taxonomyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const toTreeNodes = (locations: LocationRecord, separator: string = '/', basePat

describe('taxonomyService', () => {
describe('incrementLocationCountsAndSizes() - locationTree', () => {
// describe('#linux', () => {
for (let locationsAndExpected of [

Check failure on line 39 in server/services/taxonomyService.test.ts

View workflow job for this annotation

GitHub Actions / check (20, lint)

'locationsAndExpected' is never reassigned. Use 'const' instead
// No torrents
{locations: [] as string[], expected: toTreeNodes({'': null})[0]},
Expand Down Expand Up @@ -63,15 +64,19 @@ describe('taxonomyService', () => {

it(`builds Linux-style case-sensitive location tree correctly from ${locations}`, () => {
const taxonomyService = new TaxonomyService({} as UserInDatabase);
const spy = jest.spyOn(os, 'type');
spy.mockReturnValue('Linux');
const mock = jest.spyOn(os, 'platform');
mock.mockImplementation(() => 'linux');

for (let location of locations) taxonomyService.incrementLocationCountsAndSizes(location, 10);

Check failure on line 70 in server/services/taxonomyService.test.ts

View workflow job for this annotation

GitHub Actions / check (20, lint)

'location' is never reassigned. Use 'const' instead

expect(taxonomyService.taxonomy.locationTree).toMatchObject(expected);

mock.mockRestore();
});
}
// });

// describe('#mac', () => {
for (let locationsAndExpected of [

Check failure on line 80 in server/services/taxonomyService.test.ts

View workflow job for this annotation

GitHub Actions / check (20, lint)

'locationsAndExpected' is never reassigned. Use 'const' instead
// Multiple roots including overlapping case
{
Expand All @@ -88,13 +93,16 @@ describe('taxonomyService', () => {

it(`builds Mac-style case-insensitive location tree correctly from ${locations}`, () => {
const taxonomyService = new TaxonomyService({} as UserInDatabase);
const spy = jest.spyOn(os, 'type');
spy.mockReturnValue('Darwin');
const mock = jest.spyOn(os, 'platform');
mock.mockImplementation(() => 'darwin');

for (let location of locations) taxonomyService.incrementLocationCountsAndSizes(location, 10);

Check failure on line 99 in server/services/taxonomyService.test.ts

View workflow job for this annotation

GitHub Actions / check (20, lint)

'location' is never reassigned. Use 'const' instead

expect(taxonomyService.taxonomy.locationTree).toMatchObject(expected);

mock.mockRestore();
});
}
// });
});
});
4 changes: 2 additions & 2 deletions server/util/fileUtil.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import {promises as fsp} from 'fs';
import os, {homedir} from 'os';
import {homedir, platform} from 'os';
import path from 'path';

import config from '../../config';
Expand Down Expand Up @@ -89,4 +89,4 @@ export const sanitizePath = (input?: string): string => {
return path.resolve(input.replace(/^~/, homedir()).replace(controlRe, ''));
};

export const isInsensitiveOs = (): boolean => ['Windows_NT'].includes(os.type());
export const isInsensitiveOs = (): boolean => ['darwin', 'win32'].includes(platform());

0 comments on commit 17ec3e4

Please sign in to comment.