-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/init unit tests and jsdocs for backend and utility functions (#426)
* test: add configs and mocks for `firebase` * docs(`utilities.ts`): add jsdocs to function definitions * docs(`utilityFunctions.ts`): add jsdocs to function definitions * docs(`dbOperations.ts`): add jsdocs to function definitions * docs(`utilities.ts`): add jsdoc to function definition * docs(`utilities.ts`): add jsdocs to function definitions * test: add unit tests and setups for utilities functions * test('utilities.ts`): init unit tests * fix: fix linting issues in CI/CD * ci: change configuration for Jest to pull request * fix: invalid field `Name` in config file * fix: minor typo (transposition error) * chore(`jest.config.js`): add comment * chore(`utilities.test.ts`): reorganize tests into arrange-act-assert * chore(`utilities.test.ts`): reorganize unit tests structure/hierarchy --------- Co-authored-by: awpala <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,137 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Name: 'Jest' | ||
name: 'Jest' | ||
on: | ||
push: | ||
branches: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { DESC } from '@globals/constants'; | ||
import { TCourseId } from '@globals/types'; | ||
import { | ||
// mapRatingToColor, | ||
// mapRatingToColorInverted, | ||
mapPayloadToArray, | ||
} from '@src/utilities'; | ||
|
||
// types | ||
type TInputPayload = { | ||
// eslint-disable-next-line no-unused-vars | ||
[T in TCourseId]: any; | ||
}; | ||
|
||
describe('frontend utilities tests', () => { | ||
describe('mapRatingToColor()', () => { | ||
it('maps ratings to colors', () => { | ||
// TODO | ||
}); | ||
}); | ||
|
||
describe('mapRatingToColorInverted()', () => { | ||
it('maps ratings to inverted colors', () => { | ||
// TODO | ||
}); | ||
}); | ||
|
||
describe('mapPayloadToArray()', () => { | ||
let inputPayload: Partial<TInputPayload> = {}; | ||
|
||
beforeEach(() => { | ||
inputPayload = { | ||
'CS-6035': { sortKeyField: 3, courseId: 'CS-6035' }, | ||
'CS-6150': { sortKeyField: 1, courseId: 'CS-6150' }, | ||
'CS-6200': { sortKeyField: 2, courseId: 'CS-6200' }, | ||
}; | ||
}); | ||
|
||
it('returns empty array for empty payload', () => { | ||
const inputPayload = {}; | ||
const mappedArray = mapPayloadToArray(inputPayload); | ||
expect(mappedArray).toMatchObject([]); | ||
}); | ||
|
||
it('maps payload to array, ascending by sortKey', () => { | ||
const mappedArray = mapPayloadToArray(inputPayload, 'sortKeyField'); | ||
const expectedOutput = [ | ||
{ sortKeyField: 1, courseId: 'CS-6150' }, | ||
{ sortKeyField: 2, courseId: 'CS-6200' }, | ||
{ sortKeyField: 3, courseId: 'CS-6035' }, | ||
]; | ||
expect(mappedArray).toMatchObject(expectedOutput); | ||
}); | ||
|
||
it('maps payload to array, descending by sortKey', () => { | ||
const mappedArray = mapPayloadToArray(inputPayload, 'courseID', DESC); | ||
const expectedOutput = [ | ||
{ sortKeyField: 2, courseId: 'CS-6200' }, | ||
{ sortKeyField: 1, courseId: 'CS-6150' }, | ||
{ sortKeyField: 3, courseId: 'CS-6035' }, | ||
]; | ||
expect(mappedArray).toMatchObject(expectedOutput); | ||
}); | ||
|
||
it('falls through in original order if no sortKey specified', () => { | ||
const mappedArray = mapPayloadToArray(inputPayload); | ||
const expectedOutput = [ | ||
{ sortKeyField: 3, courseId: 'CS-6035' }, | ||
{ sortKeyField: 1, courseId: 'CS-6150' }, | ||
{ sortKeyField: 2, courseId: 'CS-6200' }, | ||
]; | ||
expect(mappedArray).toMatchObject(expectedOutput); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
jest.mock('firebase/app', () => ({ | ||
initializeApp: jest.fn(() => ({})), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jest.mock('firebase/auth', () => ({ | ||
connectAuthEmulator: jest.fn(), | ||
getAuth: jest.fn(), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
jest.mock('firebase/firestore', () => ({ | ||
getFirestore: jest.fn(() => ({ | ||
toJSON: jest.fn(() => ({ | ||
settings: { host: '' }, | ||
})), | ||
})), | ||
connectFirestoreEmulator: jest.fn(), | ||
doc: jest.fn(), | ||
getDoc: jest.fn(), | ||
setDoc: jest.fn(), | ||
deleteDoc: jest.fn(), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jest.mock('firebase/storage', () => ({ | ||
connectStorageEmulator: jest.fn(), | ||
getStorage: jest.fn(), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// mock imports (cf. `/firebase/__mocks__`) | ||
import 'firebase/app'; | ||
import 'firebase/firestore'; | ||
import 'firebase/auth'; | ||
import 'firebase/storage'; | ||
|
||
describe('backend dbOperations tests', () => { | ||
describe('courses CRUD operations', () => { | ||
describe('getCourses', () => { | ||
it('gets all courses from Firebase Firestore DB', () => { | ||
// TODO | ||
}); | ||
}); | ||
|
||
describe('getCourse()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('addCourse()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('updateCourse()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('deleteCourse()', () => { | ||
// TODO | ||
}); | ||
}); | ||
|
||
describe('reviews CRUD operations', () => { | ||
describe('getReviews()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('getReviewsRecent()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('getReview()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('addReview()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('updateReview()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('deleteReview()', () => { | ||
// TODO | ||
}); | ||
}); | ||
|
||
describe('users CRUD operations', () => { | ||
describe('getUser()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('addUser()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('editUser()', () => { | ||
// TODO | ||
}); | ||
|
||
describe('deleteUser()', () => { | ||
// TODO | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
361c1e9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
website – ./
website-git-main-omshub.vercel.app
www.omshub.org
website-omshub.vercel.app
omshub.org