Skip to content

Commit

Permalink
Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
geshuming committed Apr 16, 2020
1 parent d8f67eb commit 96d83f8
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 43 deletions.
3 changes: 2 additions & 1 deletion tests/auto-spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
export function autoSpy<T>(obj: new (...args: any[]) => T): SpyOf<T> {
const res: SpyOf<T> = {} as any;

// turns out that in target:es2015 the methods attached to the prototype are not enumerable so Object.keys returns []. So to workaround that and keep some backwards compatibility - merge with ownPropertyNames - that disregards the enumerable property.
// turns out that in target:es2015 the methods attached to the prototype are not enumerable so Object.keys returns [].
// So to workaround that and keep some backwards compatibility - merge with ownPropertyNames - that disregards the enumerable property.
const keys = [...Object.keys(obj.prototype), ...Object.getOwnPropertyNames(obj.prototype)];
keys.forEach(key => {
res[key] = jasmine.createSpy(key);
Expand Down
14 changes: 7 additions & 7 deletions tests/constants/data.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const jsonData = {
q: { 'CS2103T-W12-4': 'true' }
},
'admins-allocation': { damithc: {}, geshuming: {} }
}
};

// These are objects representing some users and teams in jsonData
const TEAM_3 = {
Expand All @@ -62,36 +62,36 @@ const TEAM_3 = {
{loginId: '003-samuel', role: UserRole.Student} ,
{loginId: 'damithc', role: UserRole.Student},
{loginId: 'ptvrajsk', role: UserRole.Student}]
}
};

const TEAM_4 = {
id: 'CS2103T-W12-4',
teamMembers: [{loginId: 'ronaklakhotia', role: UserRole.Student}]
}
};

export const USER_JUNWEI = {
loginId: 'junwei96',
role: UserRole.Student,
team: TEAM_3
}
};

export const USER_Q = {
loginId: 'q',
role: UserRole.Tutor,
allocatedTeams: [TEAM_4]
}
};

export const USER_SHUMING = {
loginId: 'geshuming',
role: UserRole.Admin,
allocatedTeams: []
}
};

export const USER_WITH_TWO_ROLES = {
loginId: 'damithc',
role: UserRole.Admin,
allocatedTeams: []
}
};

export const dataFileTeamStructure: DataFile = {
teamStructure: new Map<string, Team>([
Expand Down
8 changes: 4 additions & 4 deletions tests/constants/githubcomment.constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GithubComment } from "../../src/app/core/models/github/github-comment.model";
import { GithubComment } from '../../src/app/core/models/github/github-comment.model';

export const EMPTY_TEAM_RESPONSE : GithubComment = {
export const EMPTY_TEAM_RESPONSE: GithubComment = {
author_association: 'CONTRIBUTOR',
body: "# Team's Response\n" +
body: '# Team\'s Response\n' +
'\n' +
' ## Duplicate status (if any):\n' +
'--',
Expand All @@ -18,4 +18,4 @@ export const EMPTY_TEAM_RESPONSE : GithubComment = {
avatar_url: 'https://avatars3.githubusercontent.com/u/46639862?v=4',
url: 'https://api.github.com/users/testathorStudent',
},
}
};
8 changes: 4 additions & 4 deletions tests/constants/githubissue.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GithubIssue } from '../../src/app/core/models/github/github-issue.model';
import { GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
import { GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
GITHUB_LABEL_FUNCTIONALITY_BUG, GITHUB_LABEL_MEDIUM_SEVERITY } from '../constants/githublabel.constants';

export const ISSUE_WITH_EMPTY_DESCRIPTION = new GithubIssue({
Expand All @@ -8,7 +8,7 @@ export const ISSUE_WITH_EMPTY_DESCRIPTION = new GithubIssue({
assignees: [],
body: '',
created_at: '2020-03-02T16:19:02Z',
labels: [GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
labels: [GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
GITHUB_LABEL_FUNCTIONALITY_BUG, GITHUB_LABEL_MEDIUM_SEVERITY
],
state: 'open',
Expand All @@ -35,7 +35,7 @@ export const ISSUE_WITH_ASSIGNEES = new GithubIssue({
],
body: 'Screen freezes every few minutes',
created_at: '2020-01-18T07:01:45Z',
labels: [GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
labels: [GITHUB_LABEL_TEAM_LABEL, GITHUB_LABEL_TUTORIAL_LABEL,
GITHUB_LABEL_FUNCTIONALITY_BUG, GITHUB_LABEL_MEDIUM_SEVERITY
],
state: 'open',
Expand All @@ -48,4 +48,4 @@ export const ISSUE_WITH_ASSIGNEES = new GithubIssue({
avatar_url: 'https://avatars1.githubusercontent.com/u/35621759?v=4',
url: 'https://api.github.com/users/anubh-v',
}
} as GithubIssue);
} as GithubIssue);
10 changes: 5 additions & 5 deletions tests/constants/githublabel.constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { GithubLabel } from "../../src/app/core/models/github/github-issue.model";
import { GithubLabel } from '../../src/app/core/models/github/github-issue.model';

export const GITHUB_LABEL_FUNCTIONALITY_BUG = {
color: '9900cc',
name: 'type.FunctionalityBug',
id: 1226647550,
url: 'https://api.github.com/repos/CATcher-org/pe-results/labels/type.FunctionalityBug',
} as GithubLabel
} as GithubLabel;

export const GITHUB_LABEL_MEDIUM_SEVERITY = {
color: 'ff9999',
name: 'severity.Medium',
id: 1226647149,
url: 'https://api.github.com/repos/CATcher-org/pe-results/labels/severity.Medium',
} as GithubLabel
} as GithubLabel;

export const GITHUB_LABEL_TUTORIAL_LABEL = {
url: 'https://api.github.com/repos/CATcher-org/pe-results/labels/tutorial.CS2103T-W12',
name: 'tutorial.CS2103T-W12',
color: 'c2e0c6',
id: 1226649736,
} as GithubLabel
} as GithubLabel;

export const GITHUB_LABEL_TEAM_LABEL = {
id: 1226649835,
url: 'https://api.github.com/repos/CATcher-org/pe-results/labels/team.3',
name: 'team.3',
color: 'd4c5f9',
} as GithubLabel
} as GithubLabel;
8 changes: 4 additions & 4 deletions tests/model/issue.model.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Issue } from '../../src/app/core/models/issue.model'
import { Issue } from '../../src/app/core/models/issue.model';

import { ISSUE_WITH_EMPTY_DESCRIPTION, ISSUE_WITH_ASSIGNEES } from '../constants/githubissue.constants'
import { ISSUE_WITH_EMPTY_DESCRIPTION, ISSUE_WITH_ASSIGNEES } from '../constants/githubissue.constants';
import { EMPTY_TEAM_RESPONSE } from '../constants/githubcomment.constants';

describe('Issue model class', () => {
Expand Down Expand Up @@ -33,8 +33,8 @@ describe('Issue model class', () => {
expect(Issue.updateDescription(null)).toBe(noDetailsFromBugReporter);
expect(Issue.updateTeamResponse(undefined)).toBe(noDetailsFromTeam);

const typicalDescription = 'The app crashes after parsing config files.'
const typicalTeamResponse = 'Cannot replicate the bug.'
const typicalDescription = 'The app crashes after parsing config files.';
const typicalTeamResponse = 'Cannot replicate the bug.';
expect(Issue.updateDescription(typicalDescription)).toBe(typicalDescription);
expect(Issue.updateTeamResponse(typicalTeamResponse)).toBe(typicalTeamResponse);

Expand Down
4 changes: 2 additions & 2 deletions tests/services/application.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ApplicationService} from '../../src/app/core/services/application.service';

let applicationService = new ApplicationService(null);
const applicationService = new ApplicationService(null);
const currentVersion = '3.2.5';

describe('Test the ApplicationService', () => {
Expand All @@ -15,4 +15,4 @@ describe('Test the ApplicationService', () => {
expect(applicationService.isOutdatedVersion('3.2.6', currentVersion)).toBe(true);
expect(applicationService.isOutdatedVersion('10', currentVersion)).toBe(true);
});
});
});
12 changes: 6 additions & 6 deletions tests/services/permissions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const testStudent = {
const testTutor = {
loginId: 'testTutor',
role: UserRole.Tutor
}
};

const testAdmin = {
loginId: 'testAdmin',
role: UserRole.Admin
}
};

let mockUserService = new UserService(null, null);
let mockPhaseService = new PhaseService(null, null, null, null, null);
let permissionService = new PermissionService(null, mockUserService, mockPhaseService);
const mockUserService = new UserService(null, null);
const mockPhaseService = new PhaseService(null, null, null, null, null);
const permissionService = new PermissionService(null, mockUserService, mockPhaseService);

describe('Test a few permissions for each role in each phase', () => {
it('Test a few permissions for UserRole.Student', () => {
Expand Down Expand Up @@ -70,4 +70,4 @@ describe('Test a few permissions for each role in each phase', () => {
expect(permissionService.isIssueDeletable()).toBe(false);
expect(permissionService.isIssueTitleEditable()).toBe(false);
});
});
});
12 changes: 6 additions & 6 deletions tests/services/upload.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {UploadService, SUPPORTED_FILE_TYPES, FILE_TYPE_SUPPORT_ERROR} from '../../src/app/core/services/upload.service';

const PERIOD = "."
const PERIOD = '.';

describe('UploadService', () => {
describe('.isSupportedFileType(fileName)', () => {
it('can distinguish valid / invalid filetypes', () => {
const uploadService = new UploadService(null);
for (const validFileType of SUPPORTED_FILE_TYPES) {
const validFileName = "testFile" + PERIOD + validFileType;
const validFileName = 'testFile' + PERIOD + validFileType;
expect(uploadService.isSupportedFileType(validFileName)).toBe(true);
}
const invalidFileName = "testFile" + PERIOD + 'java';
const invalidFileName = 'testFile' + PERIOD + 'java';
expect(uploadService.isSupportedFileType(invalidFileName)).toBe(false);
});

it('is case insensitive', () => {
const uploadService = new UploadService(null);
const invalidFileName = "TESTfile" + PERIOD + "JS";
const invalidFileName = 'TESTfile' + PERIOD + 'JS';
expect(uploadService.isSupportedFileType(invalidFileName)).toBe(false);
});

it('returns false for filenames that do not have a file extension', () => {
const uploadService = new UploadService(null);
for (const validFileType of SUPPORTED_FILE_TYPES) {
const fileNameWithoutFileExtension = "testFile" + validFileType;
const fileNameWithoutFileExtension = 'testFile' + validFileType;
expect(uploadService.isSupportedFileType(fileNameWithoutFileExtension)).toBe(false);
}
});
Expand All @@ -44,4 +44,4 @@ describe('UploadService', () => {
);
});
});
});
});
8 changes: 4 additions & 4 deletions tests/services/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jsonData, USER_JUNWEI, USER_Q, USER_SHUMING, USER_WITH_TWO_ROLES } from '../constants/data.constants'
import { UserService } from '../../src/app/core/services/user.service'
import { jsonData, USER_JUNWEI, USER_Q, USER_SHUMING, USER_WITH_TWO_ROLES } from '../constants/data.constants';
import { UserService } from '../../src/app/core/services/user.service';
import { User, UserRole } from '../../src/app/core/models/user.model';
import { of } from 'rxjs';

Expand All @@ -8,7 +8,7 @@ let dataService: any;
describe('UserService', () => {
describe('.createUserModel(loginId)', () => {
beforeAll(() => {
dataService = jasmine.createSpyObj("DataService", ['getDataFile']);
dataService = jasmine.createSpyObj('DataService', ['getDataFile']);
dataService.getDataFile.and.returnValue(of(jsonData));
});

Expand Down Expand Up @@ -52,4 +52,4 @@ async function createAndVerifyUser(loginId: string, expectedUser: User) {
const userService = new UserService(null, dataService);
const actualUser = await userService.createUserModel(loginId).toPromise();
expect(actualUser).toEqual(expectedUser);
}
}

0 comments on commit 96d83f8

Please sign in to comment.