-
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.
Merge pull request #79 from GuoXiCheng/dev-c
Dev c
- Loading branch information
Showing
13 changed files
with
338 additions
and
43 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 |
---|---|---|
|
@@ -130,3 +130,4 @@ dist | |
.pnp.* | ||
|
||
lib | ||
src/__tests__/mock/json/*.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { githubRequest } from "../helper/helper"; | ||
import { mockGithubUser } from "../mock/mock-github-user"; | ||
|
||
describe('Test Fake Authenticate Github', () => { | ||
test('Test Authenticate Github', async () => { | ||
mockGithubUser(); | ||
const res = await githubRequest.authenticate(); | ||
expect(res).toEqual({ | ||
login: '***', | ||
id: 1000001, | ||
node_id: '***', | ||
avatar_url: 'https://avatars.githubusercontent.com/u/***?v=4', | ||
gravatar_id: '', | ||
url: 'https://api.github.com/users/***', | ||
html_url: 'https://github.com/***', | ||
followers_url: 'https://api.github.com/users/***/followers', | ||
following_url: 'https://api.github.com/users/***/following{/other_user}', | ||
gists_url: 'https://api.github.com/users/***/gists{/gist_id}', | ||
starred_url: 'https://api.github.com/users/***/starred{/owner}{/repo}', | ||
subscriptions_url: 'https://api.github.com/users/***/subscriptions', | ||
organizations_url: 'https://api.github.com/users/***/orgs', | ||
repos_url: 'https://api.github.com/users/***/repos', | ||
events_url: 'https://api.github.com/users/***/events{/privacy}', | ||
received_events_url: 'https://api.github.com/users/***/received_events', | ||
type: 'User', | ||
site_admin: false, | ||
name: '***', | ||
company: null, | ||
blog: '***.github.io', | ||
location: '***', | ||
email: null, | ||
hireable: null, | ||
bio: '***', | ||
twitter_username: null, | ||
public_repos: 0, | ||
public_gists: 0, | ||
followers: 0, | ||
following: 0, | ||
created_at: '2017-12-04T12:29:35Z', | ||
updated_at: '2023-12-17T04:01:22Z' | ||
}); | ||
}); | ||
}); |
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,51 @@ | ||
import { gitlabRequest } from "../helper/helper"; | ||
import { mockGitlabUser } from "../mock/mock-gitlab-user"; | ||
|
||
describe('Test Fake Authenticate Gitlab', () => { | ||
test('Test Authenticate Gitlab', async () => { | ||
mockGitlabUser(); | ||
const res = await gitlabRequest.authenticate(); | ||
expect(res).toEqual({ | ||
id: 100001, | ||
username: '***', | ||
name: '***', | ||
state: 'active', | ||
locked: false, | ||
avatar_url: 'https://secure.gravatar.com/avatar/***?s=80&d=identicon', | ||
web_url: 'https://gitlab.com/***', | ||
created_at: '2023-12-21T02:56:43.269Z', | ||
bio: '', | ||
location: '', | ||
public_email: null, | ||
skype: '', | ||
linkedin: '', | ||
twitter: '', | ||
discord: '', | ||
website_url: '', | ||
organization: '', | ||
job_title: '', | ||
pronouns: null, | ||
bot: true, | ||
work_information: null, | ||
local_time: null, | ||
last_sign_in_at: null, | ||
confirmed_at: '2023-12-21T02:56:43.230Z', | ||
last_activity_on: '2024-01-12', | ||
email: '***@noreply.gitlab.com', | ||
theme_id: 0, | ||
color_scheme_id: 0, | ||
projects_limit: 0, | ||
current_sign_in_at: null, | ||
identities: [], | ||
can_create_group: true, | ||
can_create_project: true, | ||
two_factor_enabled: false, | ||
external: false, | ||
private_profile: false, | ||
commit_email: '***@noreply.gitlab.com', | ||
shared_runners_minutes_limit: null, | ||
extra_shared_runners_minutes_limit: null, | ||
scim_identities: [] | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
import { User } from "../helper/user-repository"; | ||
import { initGiteeJSONFile, mockGiteeCreate, mockGiteeFind, mockGiteeFindById } from "../mock/mock-gitee-api"; | ||
|
||
describe('Test Fake User Repository', () => { | ||
beforeAll(async ()=>{ | ||
await initGiteeJSONFile(); | ||
}); | ||
|
||
test('Test find User', async () => { | ||
await mockGiteeFind(); | ||
const detail = await User.find(); | ||
expect(detail.length).toEqual(0); | ||
}); | ||
|
||
test('Test create & findById User', async () => { | ||
await mockGiteeCreate(); | ||
await User.create({ | ||
name: 'test-user', | ||
age: 18 | ||
}); | ||
|
||
await mockGiteeFind(); | ||
const findResult = await User.find(); | ||
expect(findResult.length).toEqual(1); | ||
|
||
await mockGiteeFindById(findResult[0].id); | ||
const findByIdResult = await User.findById(findResult[0].id); | ||
expect(findByIdResult).toEqual(findResult[0]); | ||
expect(findByIdResult.created_by).not.toBeNull(); | ||
expect(typeof findByIdResult.created_by.user_id).toBe('number'); | ||
expect(typeof findByIdResult.created_by.username).toBe('string'); | ||
expect(typeof findByIdResult.created_by.avatar_url).toBe('string'); | ||
}); | ||
}); |
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
Empty file.
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,42 @@ | ||
import dayjs from "dayjs"; | ||
import { GITEE_NUMBER, GITEE_OWNER, GITEE_REPO, mock } from "../helper/helper"; | ||
import jsonfile from 'jsonfile'; | ||
|
||
const filepath = 'src/__tests__/mock/json/gitee.json'; | ||
|
||
export async function initGiteeJSONFile() { | ||
await jsonfile.writeFile(filepath, []); | ||
} | ||
|
||
export async function mockGiteeFind() { | ||
const result = await jsonfile.readFile(filepath); | ||
mock.onGet(`https://gitee.com/api/v5/repos/${GITEE_OWNER}/${GITEE_REPO}/issues/${GITEE_NUMBER}/comments`).reply(200, result); | ||
} | ||
|
||
export async function mockGiteeFindById(id: number) { | ||
mock.onGet(`https://gitee.com/api/v5/repos/${GITEE_OWNER}/${GITEE_REPO}/issues/comments/${id}`).reply(async (config) => { | ||
const result = await jsonfile.readFile(filepath); | ||
return [200, result.find((item: any) => item.id === id)]; | ||
}); | ||
} | ||
|
||
export async function mockGiteeCreate() { | ||
mock.onPost(`https://gitee.com/api/v5/repos/${GITEE_OWNER}/${GITEE_REPO}/issues/${GITEE_NUMBER}/comments`).reply(async (config) => { | ||
const result = await jsonfile.readFile(filepath); | ||
const data = { | ||
id: Math.round(Math.random() * 1000000), | ||
body: JSON.parse(config.data).body, | ||
user: { | ||
id: 100001, | ||
login: "***", | ||
name: "***", | ||
avatar_url: "https://foruda.gitee.com/avatar/***/***.png", | ||
}, | ||
created_at: dayjs().format(), | ||
updated_at: dayjs().format() | ||
}; | ||
result.push(data) | ||
await jsonfile.writeFile(filepath, result, {spaces: 2}); | ||
return [200, data]; | ||
}); | ||
} |
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,35 @@ | ||
import { mock } from "../helper/helper"; | ||
|
||
export function mockGiteeUser() { | ||
mock.onGet('https://gitee.com/api/v5/user').reply(200, { | ||
"id": 1000001, | ||
"login": "***", | ||
"name": "***", | ||
"avatar_url": "https://foruda.gitee.com/avatar/***/***.png", | ||
"url": "https://gitee.com/api/v5/users/***", | ||
"html_url": "https://gitee.com/***", | ||
"remark": "", | ||
"followers_url": "https://gitee.com/api/v5/users/***/followers", | ||
"following_url": "https://gitee.com/api/v5/users/***/following_url{/other_user}", | ||
"gists_url": "https://gitee.com/api/v5/users/***/gists{/gist_id}", | ||
"starred_url": "https://gitee.com/api/v5/users/***/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://gitee.com/api/v5/users/***/subscriptions", | ||
"organizations_url": "https://gitee.com/api/v5/users/***/orgs", | ||
"repos_url": "https://gitee.com/api/v5/users/***/repos", | ||
"events_url": "https://gitee.com/api/v5/users/***/events{/privacy}", | ||
"received_events_url": "https://gitee.com/api/v5/users/***/received_events", | ||
"type": "User", | ||
"blog": null, | ||
"weibo": null, | ||
"bio": "", | ||
"public_repos": 0, | ||
"public_gists": 0, | ||
"followers": 0, | ||
"following": 0, | ||
"stared": 0, | ||
"watched": 0, | ||
"created_at": "2020-02-26T13:20:27+08:00", | ||
"updated_at": "2024-01-10T22:27:59+08:00", | ||
"email": null | ||
}); | ||
} |
Oops, something went wrong.