-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The initial docs I'd found on user search were wrong. I now realise querying will have to be a multi-step process. This gives me a great opportunity to use resolvers to solve this
- Loading branch information
1 parent
171b86f
commit 51fea2d
Showing
20 changed files
with
279 additions
and
206 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,32 +1,56 @@ | ||
import { UserSearchPage } from '@backend/domain' | ||
import { SearchService } from '@backend/services' | ||
import { User, UserResult, UserSearchPage } from '@backend/domain' | ||
import { UserService } from '@backend/services' | ||
import { gql } from 'apollo-server' | ||
import { IContext } from './context' | ||
import { createGraphQLServer } from './create-graphql-server' | ||
|
||
const mockSearchUsers = jest.fn() | ||
const mockFetchUser = jest.fn() | ||
|
||
class MockSearchService extends SearchService { | ||
searchUsers = mockSearchUsers | ||
class MockSearchService extends UserService { | ||
findUsers = mockSearchUsers | ||
fetchUser = mockFetchUser | ||
} | ||
|
||
const context = () => ({ | ||
const context = (): IContext => ({ | ||
services: { | ||
search: new MockSearchService(), | ||
user: new MockSearchService(), | ||
}, | ||
}) | ||
|
||
it('should respond with test results', async () => { | ||
const server = await createGraphQLServer(context) | ||
|
||
mockSearchUsers.mockResolvedValue(new UserSearchPage(0, false, [])) | ||
mockSearchUsers.mockResolvedValue( | ||
new UserSearchPage(0, false, [new UserResult('test-user', [])]) | ||
) | ||
mockFetchUser.mockResolvedValue( | ||
new User( | ||
'test-user', | ||
'http://nuwis.co/wo', | ||
'http://og.na/gat', | ||
642549735, | ||
983133452, | ||
630987351, | ||
1254879450, | ||
'Leroy Phelps', | ||
null, | ||
null, | ||
'[email protected]', | ||
'Dolgicwa' | ||
) | ||
) | ||
|
||
const { data, errors } = await server.executeOperation({ | ||
query: gql` | ||
query testSearch { | ||
searchUsers(query: "test-query", page: 3) { | ||
resultsCount | ||
results { | ||
login | ||
user { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -37,8 +61,16 @@ it('should respond with test results', async () => { | |
expect(data).toMatchObject({ | ||
searchUsers: { | ||
resultsCount: 0, | ||
results: [], | ||
results: [ | ||
{ | ||
user: { | ||
id: 'test-user', | ||
name: 'Leroy Phelps', | ||
}, | ||
}, | ||
], | ||
}, | ||
}) | ||
expect(mockSearchUsers).toHaveBeenCalledWith('test-query', 3) | ||
expect(mockFetchUser).toHaveBeenCalledWith('test-user') | ||
}) |
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
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.