-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get profile authenticate option
- Loading branch information
Showing
4 changed files
with
140 additions
and
45 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
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 |
---|---|---|
|
@@ -1076,22 +1076,22 @@ describe('client', () => { | |
}); | ||
}); | ||
describe('getProfile', () => { | ||
it('should get one profile', async () => { | ||
const mockResult: ProfileVersionResponse = { | ||
profile_id: 'testId', | ||
profile_name: 'testName', | ||
profile_version: '1.0.0', | ||
url: 'testUrl', | ||
published_at: new Date(), | ||
published_by: 'test', | ||
owner: 'testOwner', | ||
owner_url: 'testOwnerUrl', | ||
}; | ||
const mockResult: ProfileVersionResponse = { | ||
profile_id: 'testId', | ||
profile_name: 'testName', | ||
profile_version: '1.0.0', | ||
url: 'testUrl', | ||
published_at: new Date(), | ||
published_by: 'test', | ||
owner: 'testOwner', | ||
owner_url: 'testOwnerUrl', | ||
}; | ||
const mockResponse = { | ||
ok: true, | ||
json: async () => mockResult, | ||
}; | ||
|
||
const mockResponse = { | ||
ok: true, | ||
json: async () => mockResult, | ||
}; | ||
it('should get one profile', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
|
@@ -1112,6 +1112,29 @@ describe('client', () => { | |
}); | ||
}); | ||
|
||
it('should authenticate user', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
await client.getProfile( | ||
{ | ||
name: 'user-repos', | ||
version: '1.0.0', | ||
scope: 'vcs', | ||
}, | ||
{ | ||
authenticate: true, | ||
} | ||
); | ||
expect(fetchMock).toBeCalledWith('/vcs/[email protected]', { | ||
authenticate: true, | ||
method: 'GET', | ||
headers: { | ||
Accept: MEDIA_TYPE_JSON, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should throw error', async () => { | ||
const payload = { | ||
status: 404, | ||
|
@@ -1145,21 +1168,21 @@ describe('client', () => { | |
}); | ||
|
||
describe('getProfilesList', () => { | ||
it('should get list of profiles', async () => { | ||
const mockResult: ProfilesListResponse = { | ||
url: '/profiles', | ||
data: [ | ||
{ | ||
id: 'scope/profile-name', | ||
url: 'https://superface.test/scope/profile-name', | ||
}, | ||
], | ||
}; | ||
const mockResult: ProfilesListResponse = { | ||
url: '/profiles', | ||
data: [ | ||
{ | ||
id: 'scope/profile-name', | ||
url: 'https://superface.test/scope/profile-name', | ||
}, | ||
], | ||
}; | ||
const mockResponse = { | ||
ok: true, | ||
json: async () => mockResult, | ||
}; | ||
|
||
const mockResponse = { | ||
ok: true, | ||
json: async () => mockResult, | ||
}; | ||
it('should get list of profiles', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
|
@@ -1192,6 +1215,18 @@ describe('client', () => { | |
); | ||
}); | ||
|
||
it('should authenticate user', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
await client.getProfilesList({ authenticate: true }); | ||
expect(fetchMock).toBeCalledWith('/profiles', { | ||
authenticate: true, | ||
method: 'GET', | ||
headers: { Accept: MEDIA_TYPE_JSON }, | ||
}); | ||
}); | ||
|
||
it('should throw error', async () => { | ||
const payload = { | ||
status: 400, | ||
|
@@ -1219,11 +1254,12 @@ describe('client', () => { | |
}); | ||
|
||
describe('getProfileSource', () => { | ||
const mockResponse = { | ||
ok: true, | ||
text: async () => 'profileSource', | ||
}; | ||
|
||
it('should get profile source', async () => { | ||
const mockResponse = { | ||
ok: true, | ||
text: async () => 'profileSource', | ||
}; | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
|
@@ -1244,6 +1280,27 @@ describe('client', () => { | |
}); | ||
}); | ||
|
||
it('should authenticate user', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
await client.getProfileSource( | ||
{ | ||
name: 'user-repos', | ||
version: '1.0.0', | ||
scope: 'vcs', | ||
}, | ||
{ authenticate: true } | ||
); | ||
expect(fetchMock).toBeCalledWith('/vcs/[email protected]', { | ||
authenticate: true, | ||
method: 'GET', | ||
headers: { | ||
Accept: MEDIA_TYPE_PROFILE, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should throw error', async () => { | ||
const payload = { | ||
status: 404, | ||
|
@@ -1277,11 +1334,12 @@ describe('client', () => { | |
}); | ||
|
||
describe('getProfileAST', () => { | ||
const mockResponse = { | ||
ok: true, | ||
text: async () => 'profileAST', | ||
}; | ||
|
||
it('should get profile AST', async () => { | ||
const mockResponse = { | ||
ok: true, | ||
text: async () => 'profileAST', | ||
}; | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
|
@@ -1302,6 +1360,27 @@ describe('client', () => { | |
}); | ||
}); | ||
|
||
it('should authenticate user', async () => { | ||
const fetchMock = jest | ||
.spyOn(client, 'fetch') | ||
.mockResolvedValue(mockResponse as Response); | ||
await client.getProfileAST( | ||
{ | ||
name: 'user-repos', | ||
version: '1.0.0', | ||
scope: 'vcs', | ||
}, | ||
{ authenticate: true } | ||
); | ||
expect(fetchMock).toBeCalledWith('/vcs/[email protected]', { | ||
authenticate: true, | ||
method: 'GET', | ||
headers: { | ||
Accept: MEDIA_TYPE_PROFILE_AST, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should throw error', async () => { | ||
const payload = { | ||
status: 404, | ||
|
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export interface ProfilesListOptions { | ||
export interface ProfilesListOptions extends ProfileOptions { | ||
limit?: number; | ||
accountHandle?: string; | ||
} | ||
|
||
export interface ProfileOptions { | ||
authenticate?: boolean; | ||
} |