-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add backend API unit tests #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 20 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
e62ea91
setting up test structure
O-Bots 0add06b
.
O-Bots ae75bdb
added playwright config file, deleted original playwright folder and …
O-Bots b3a6b31
continued test structure setup
O-Bots d91d2af
Updating test folder structure
O-Bots 68011f8
Merge branch 'main' into main
O-Bots 8671300
Merge branch 'CompassConnections:main' into main
O-Bots b13b8d4
Merge branch 'CompassConnections:main' into main
O-Bots 266a2b4
Added database seeding script and backend testing folder structure
O-Bots 062b6f2
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots 18f24e2
removed the database test
O-Bots c949891
Replaced db seeding script
O-Bots dfd5b6f
Updated userInformation.ts to use values from choices.tsx
O-Bots 8bd9f45
merge prep
O-Bots 834c433
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots 7115c22
removing extra unit test, moving api test to correct folder
O-Bots c039a10
Merge branch 'CompassConnections:main' into main
O-Bots 750d7c9
Pushing to get help with sql Unit test
O-Bots a7f36c5
Merge branch 'main' of https://github.com/O-Bots/Obots_Compass
O-Bots e30eac9
Merge branch 'main' into main
O-Bots f3f2ebf
Updating get-profiles unit tests
O-Bots 48ef836
Added more unit tests
O-Bots ea7ef9c
.
O-Bots 443996a
Added more unit tests
O-Bots 10f17af
Added getSupabaseToken unit test
O-Bots a0e48aa
.
O-Bots f96c122
excluding supabase token test so ci can pass
O-Bots 2a4b002
.
O-Bots f9bebe3
Seperated the seedDatabase func into its own file so it can be access…
O-Bots 4cd3327
Fixed failing test
O-Bots 25e4d91
.
O-Bots 6f014bb
.
O-Bots da0a911
Merge branch 'refs/heads/main' into fork/O-Bots/main
MartinBraquet d658211
Fix tests
MartinBraquet d76fd2a
Fix lint
MartinBraquet 0359742
Clean
MartinBraquet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,143 @@ | ||
| import * as profilesModule from "api/get-profiles"; | ||
| import { Profile } from "common/profiles/profile"; | ||
| import { createSupabaseDirectClient } from "shared/supabase/init"; | ||
| import { renderSql } from "shared/supabase/sql-builder"; | ||
|
|
||
| jest.mock("shared/supabase/init") | ||
|
|
||
| // describe.skip('getProfiles', () => { | ||
| // beforeEach(() => { | ||
| // jest.clearAllMocks(); | ||
| // }); | ||
|
|
||
| // describe('should fetch the user profiles', () => { | ||
| // it('successfully', async ()=> { | ||
| // const mockProfiles = [ | ||
| // { | ||
| // diet: ['Jonathon Hammon'], | ||
| // has_kids: 0 | ||
| // }, | ||
| // { | ||
| // diet: ['Joseph Hammon'], | ||
| // has_kids: 1 | ||
| // }, | ||
| // { | ||
| // diet: ['Jolene Hammon'], | ||
| // has_kids: 2, | ||
| // } | ||
| // ] as Profile []; | ||
|
|
||
| // jest.spyOn(profilesModule, 'loadProfiles').mockResolvedValue(mockProfiles); | ||
|
|
||
| // const props = { | ||
| // limit: 2, | ||
| // orderBy: "last_online_time" as const, | ||
| // }; | ||
| // const mockReq = {} as any; | ||
| // const results = await profilesModule.getProfiles(props, mockReq, mockReq); | ||
|
|
||
| // if('continue' in results) { | ||
| // throw new Error('Expected direct response') | ||
| // }; | ||
|
|
||
| // expect(results.status).toEqual('success'); | ||
| // expect(results.profiles).toEqual(mockProfiles); | ||
| // expect(results.profiles[0]).toEqual(mockProfiles[0]); | ||
| // expect(profilesModule.loadProfiles).toHaveBeenCalledWith(props); | ||
| // expect(profilesModule.loadProfiles).toHaveBeenCalledTimes(1); | ||
| // }); | ||
|
|
||
| // it('unsucessfully', async () => { | ||
| // jest.spyOn(profilesModule, 'loadProfiles').mockRejectedValue(null); | ||
|
|
||
| // const props = { | ||
| // limit: 2, | ||
| // orderBy: "last_online_time" as const, | ||
| // }; | ||
| // const mockReq = {} as any; | ||
| // const results = await profilesModule.getProfiles(props, mockReq, mockReq); | ||
|
|
||
| // if('continue' in results) { | ||
| // throw new Error('Expected direct response') | ||
| // }; | ||
|
|
||
| // expect(results.status).toEqual('fail'); | ||
| // expect(results.profiles).toEqual([]); | ||
| // expect(profilesModule.loadProfiles).toHaveBeenCalledWith(props); | ||
| // expect(profilesModule.loadProfiles).toHaveBeenCalledTimes(1); | ||
| // }); | ||
|
|
||
| // }); | ||
| // }); | ||
|
|
||
| describe('loadProfiles', () => { | ||
| let mockPg: any; | ||
|
|
||
| describe('should', () => { | ||
| beforeEach(() => { | ||
| mockPg = { | ||
| map: jest.fn().mockResolvedValue([]), | ||
| }; | ||
|
|
||
| (createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg) | ||
| jest.clearAllMocks(); | ||
| }); | ||
| it('call pg.map with an SQL query', async () => { | ||
| await profilesModule.loadProfiles({ | ||
| limit: 10, | ||
| name: 'John', | ||
| is_smoker: true, | ||
| }); | ||
|
|
||
| const sqlQuery = mockPg.map.mock.calls | ||
| console.log(sqlQuery); | ||
|
|
||
| }); | ||
| }); | ||
|
|
||
| // describe.skip('should', () => { | ||
| // beforeEach(() => { | ||
| // mockPg = { | ||
| // map: jest.fn(), | ||
| // }; | ||
|
|
||
| // (createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg) | ||
|
|
||
| // jest.clearAllMocks(); | ||
| // }); | ||
| // it('return profiles from the database', async () => { | ||
| // const mockProfiles = [ | ||
| // { | ||
| // diet: ['Jonathon Hammon'], | ||
| // is_smoker: true, | ||
| // has_kids: 0 | ||
| // }, | ||
| // { | ||
| // diet: ['Joseph Hammon'], | ||
| // is_smoker: false, | ||
| // has_kids: 1 | ||
| // }, | ||
| // { | ||
| // diet: ['Jolene Hammon'], | ||
| // is_smoker: true, | ||
| // has_kids: 2, | ||
| // } | ||
| // ] as Profile []; | ||
|
|
||
| // mockPg.map.mockResolvedValue(mockProfiles); | ||
| // const props = {} as any; | ||
| // const results = await profilesModule.loadProfiles(props); | ||
|
|
||
| // expect(results).toEqual(mockProfiles); | ||
| // }); | ||
| // }) | ||
| }) | ||
|
|
||
| // const test = profilesModule.loadProfiles({ | ||
| // limit: 10, | ||
| // name: 'Noah Boyer', | ||
| // // is_smoker: true, | ||
| // // orderBy: 'created_time' | ||
| // }); | ||
| // test.then(res => {console.log(res); | ||
| // }) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.