From b23510bf9ff4e3028d34a5e5cc2d73c47952f01a Mon Sep 17 00:00:00 2001 From: GuoXiCheng <1377994267@qq.com> Date: Sun, 14 Jan 2024 18:29:57 +0800 Subject: [PATCH] update test --- .gitignore | 3 +- src/__tests__/fake/authenticate-gitee.test.ts | 50 ++-- .../fake/authenticate-github.test.ts | 54 ++--- .../fake/authenticate-gitlab.test.ts | 86 +++---- src/__tests__/fake/user-repository.test.ts | 27 +-- src/__tests__/helper/helper.ts | 7 +- .../mock/json/mock-gitee-detail.json | 224 +++++++++++++++++ src/__tests__/mock/json/mock-gitee-user.json | 31 +++ src/__tests__/mock/json/mock-github-user.json | 34 +++ src/__tests__/mock/json/mock-gitlab-user.json | 42 ++++ src/__tests__/mock/mock-git-user.ts | 19 ++ src/__tests__/mock/mock-gitee-api.ts | 227 +----------------- src/__tests__/mock/mock-gitee-user.ts | 35 --- src/__tests__/mock/mock-github-user.ts | 38 --- src/__tests__/mock/mock-gitlab-user.ts | 46 ---- 15 files changed, 448 insertions(+), 475 deletions(-) create mode 100644 src/__tests__/mock/json/mock-gitee-detail.json create mode 100644 src/__tests__/mock/json/mock-gitee-user.json create mode 100644 src/__tests__/mock/json/mock-github-user.json create mode 100644 src/__tests__/mock/json/mock-gitlab-user.json create mode 100644 src/__tests__/mock/mock-git-user.ts delete mode 100644 src/__tests__/mock/mock-gitee-user.ts delete mode 100644 src/__tests__/mock/mock-github-user.ts delete mode 100644 src/__tests__/mock/mock-gitlab-user.ts diff --git a/.gitignore b/.gitignore index 65a6be0..83bd64a 100644 --- a/.gitignore +++ b/.gitignore @@ -130,4 +130,5 @@ dist .pnp.* lib -src/__tests__/mock/json/*.json \ No newline at end of file +src/__tests__/mock/json/*.json +!src/__tests__/mock/json/mock*.json \ No newline at end of file diff --git a/src/__tests__/fake/authenticate-gitee.test.ts b/src/__tests__/fake/authenticate-gitee.test.ts index 47798ae..82745a3 100644 --- a/src/__tests__/fake/authenticate-gitee.test.ts +++ b/src/__tests__/fake/authenticate-gitee.test.ts @@ -1,40 +1,26 @@ import { giteeRequest } from '../helper/helper'; -import { mockGiteeUser } from '../mock/mock-gitee-user'; +import { mockGiteeUser } from '../mock/mock-git-user'; describe('Test Fake Authenticate Gitee', () => { test('Test Authenticate Gitee', async () => { mockGiteeUser(); const res = await giteeRequest.authenticate(); - expect(res).toEqual({ - 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 - }); + expect(Object.keys(res)).toEqual([ + 'id', 'login', + 'name', 'avatar_url', + 'url', 'html_url', + 'remark', 'followers_url', + 'following_url', 'gists_url', + 'starred_url', 'subscriptions_url', + 'organizations_url', 'repos_url', + 'events_url', 'received_events_url', + 'type', 'blog', + 'weibo', 'bio', + 'public_repos', 'public_gists', + 'followers', 'following', + 'stared', 'watched', + 'created_at', 'updated_at', + 'email' + ]); }); }); \ No newline at end of file diff --git a/src/__tests__/fake/authenticate-github.test.ts b/src/__tests__/fake/authenticate-github.test.ts index 4ef038c..b0d2d01 100644 --- a/src/__tests__/fake/authenticate-github.test.ts +++ b/src/__tests__/fake/authenticate-github.test.ts @@ -1,43 +1,27 @@ import { githubRequest } from "../helper/helper"; -import { mockGithubUser } from "../mock/mock-github-user"; +import { mockGithubUser } from "../mock/mock-git-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' - }); + expect(Object.keys(res)).toEqual([ + 'login', 'id', + 'node_id', 'avatar_url', + 'gravatar_id', 'url', + 'html_url', 'followers_url', + 'following_url', 'gists_url', + 'starred_url', 'subscriptions_url', + 'organizations_url', 'repos_url', + 'events_url', 'received_events_url', + 'type', 'site_admin', + 'name', 'company', + 'blog', 'location', + 'email', 'hireable', + 'bio', 'twitter_username', + 'public_repos', 'public_gists', + 'followers', 'following', + 'created_at', 'updated_at' + ]); }); }); \ No newline at end of file diff --git a/src/__tests__/fake/authenticate-gitlab.test.ts b/src/__tests__/fake/authenticate-gitlab.test.ts index d5f467f..bdb2e0a 100644 --- a/src/__tests__/fake/authenticate-gitlab.test.ts +++ b/src/__tests__/fake/authenticate-gitlab.test.ts @@ -1,51 +1,51 @@ import { gitlabRequest } from "../helper/helper"; -import { mockGitlabUser } from "../mock/mock-gitlab-user"; +import { mockGitlabUser } from "../mock/mock-git-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: [] - }); + expect(Object.keys(res)).toEqual([ + 'id', + 'username', + 'name', + 'state', + 'locked', + 'avatar_url', + 'web_url', + 'created_at', + 'bio', + 'location', + 'public_email', + 'skype', + 'linkedin', + 'twitter', + 'discord', + 'website_url', + 'organization', + 'job_title', + 'pronouns', + 'bot', + 'work_information', + 'local_time', + 'last_sign_in_at', + 'confirmed_at', + 'last_activity_on', + 'email', + 'theme_id', + 'color_scheme_id', + 'projects_limit', + 'current_sign_in_at', + 'identities', + 'can_create_group', + 'can_create_project', + 'two_factor_enabled', + 'external', + 'private_profile', + 'commit_email', + 'shared_runners_minutes_limit', + 'extra_shared_runners_minutes_limit', + 'scim_identities' + ]); }); }); \ No newline at end of file diff --git a/src/__tests__/fake/user-repository.test.ts b/src/__tests__/fake/user-repository.test.ts index 7a61562..7468f9e 100644 --- a/src/__tests__/fake/user-repository.test.ts +++ b/src/__tests__/fake/user-repository.test.ts @@ -4,6 +4,7 @@ import { UserModel } from "../helper/user-model"; import { User } from "../helper/user-repository"; import { initGiteeJSONFile, mockGiteeCreate, mockGiteeDeleteById, mockGiteeDetail, mockGiteeFind, mockGiteeFindById, mockGiteeUpdateById } from "../mock/mock-gitee-api"; + describe('Test Fake User Repository', () => { const userList: PlainObject[] = [{ name: 'test-user-1', @@ -46,28 +47,30 @@ describe('Test Fake User Repository', () => { age: 36 }]; - beforeAll(async ()=>{ + beforeAll(async ()=>{ await initGiteeJSONFile(); + await mockGiteeFind(); + await mockGiteeCreate(); + await mockGiteeFindById(); + await mockGiteeUpdateById(); + await mockGiteeDeleteById(); + await mockGiteeDetail(); }); 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(); const findByIdResult = await User.findById(findResult[0].id); expect(findByIdResult).toEqual(findResult[0]); expect(findByIdResult.created_by).not.toBeNull(); @@ -77,16 +80,12 @@ describe('Test Fake User Repository', () => { }); test('Test updateById User', async () => { - await mockGiteeFind(); const findResult = await User.find(); - - await mockGiteeUpdateById(); const updateResult = await User.updateById(findResult[0].id, { name: 'test-user-update', age: 20 }); - await mockGiteeFindById(); const findByIdResult = await User.findById(findResult[0].id); expect(updateResult.name).toEqual(findByIdResult.name); expect(updateResult.age).toEqual(findByIdResult.age); @@ -97,7 +96,6 @@ describe('Test Fake User Repository', () => { test('Test deleteById User failed', async () => { try { - await mockGiteeDeleteById(); await User.deleteById(123); } catch (error: any) { expect(error.response.data).toEqual({ message: '404 Not Found' }); @@ -118,7 +116,6 @@ describe('Test Fake User Repository', () => { test('Test findById User failed', async () => { try { - await mockGiteeFindById(); await User.findById(123); } catch (error: any) { expect(error.response.data).toEqual({ message: '404 Not Found' }); @@ -126,10 +123,6 @@ describe('Test Fake User Repository', () => { }); test('Test createAll User orderly', async () => { - await mockGiteeFind(); - await mockGiteeDeleteById(); - await mockGiteeCreate(); - await User.deleteAll(); const result = await User.createAll(userList, true); expect(result.length).toEqual(10); @@ -140,7 +133,6 @@ describe('Test Fake User Repository', () => { test('Test find user with params since', async () => { const time = dayjs().subtract(3, 'second').format(); - await mockGiteeFind(); const result = await User.find({ since: time }); expect(result.length).toBeGreaterThan(0); result.forEach(item => { @@ -149,7 +141,6 @@ describe('Test Fake User Repository', () => { }); test('Test find user with params order', async () => { - await mockGiteeFind(); const resultDesc = await User.find({ order: 'desc' }); expect(resultDesc.map(item => item.name)).toEqual(userList.map(item => item.name).reverse()); @@ -158,7 +149,6 @@ describe('Test Fake User Repository', () => { }); test('Test find user with params page & per_page', async () => { - await mockGiteeFind(); const firstPage = await User.find({ page: 1, per_page: 3 }); expect(firstPage.length).toEqual(3); @@ -167,7 +157,6 @@ describe('Test Fake User Repository', () => { }); test('Test get User Detail', async()=>{ - await mockGiteeDetail(); const result = await User.detail(); const {id, issue_number, comments, created_at, updated_at} = result; expect(id).not.toBeNull(); diff --git a/src/__tests__/helper/helper.ts b/src/__tests__/helper/helper.ts index dd94ab8..a755b65 100644 --- a/src/__tests__/helper/helper.ts +++ b/src/__tests__/helper/helper.ts @@ -6,6 +6,7 @@ import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; import MockAdapter from 'axios-mock-adapter'; +import jsonfile from 'jsonfile'; export const mock = new MockAdapter(axios); @@ -62,4 +63,8 @@ export const gitlabRequest = createRequest({ accessToken: process.env.TEST_GITLAB_TOKEN as string, platform: 'gitlab', projectId: process.env.TEST_GITLAB_PROJECT_ID as string -}); \ No newline at end of file +}); + +export function readJSONSync(filename: string) { + return jsonfile.readFileSync(`src/__tests__/mock/json/${filename}`); +} \ No newline at end of file diff --git a/src/__tests__/mock/json/mock-gitee-detail.json b/src/__tests__/mock/json/mock-gitee-detail.json new file mode 100644 index 0000000..08f505b --- /dev/null +++ b/src/__tests__/mock/json/mock-gitee-detail.json @@ -0,0 +1,224 @@ +{ + "id": 100001, + "url": "https://gitee.com/api/v5/repos/***/***/issues/***", + "repository_url": "https://gitee.com/api/v5/repos/***/***", + "labels_url": "https://gitee.com/api/v5/repos/***/***/issues/***/labels", + "comments_url": "https://gitee.com/api/v5/repos/***/***/issues/***/comments", + "html_url": "https://gitee.com/***/***/issues/***", + "parent_url": null, + "number": "***", + "parent_id": 0, + "depth": 0, + "state": "open", + "title": "***", + "body": "test body", + "user": { + "id": 100001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" + }, + "labels": [], + "assignee": null, + "collaborators": [], + "repository": { + "id": 100001, + "full_name": "***/***", + "human_name": "***/***", + "url": "https://gitee.com/api/v5/repos/***/***", + "namespace": { + "id": 100001, + "type": "personal", + "name": "***", + "path": "***", + "html_url": "https://gitee.com/***" + }, + "path": "***", + "name": "***", + "owner": { + "id": 100001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" + }, + "assigner": { + "id": 100001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" + }, + "description": "", + "private": true, + "public": false, + "internal": false, + "fork": false, + "html_url": "https://gitee.com/***/***.git", + "ssh_url": "git@gitee.com:***/***.git", + "forks_url": "https://gitee.com/api/v5/repos/***/***/forks", + "keys_url": "https://gitee.com/api/v5/repos/***/***/keys{/key_id}", + "collaborators_url": "https://gitee.com/api/v5/repos/***/***/collaborators{/collaborator}", + "hooks_url": "https://gitee.com/api/v5/repos/***/***/hooks", + "branches_url": "https://gitee.com/api/v5/repos/***/***/branches{/branch}", + "tags_url": "https://gitee.com/api/v5/repos/***/***/tags", + "blobs_url": "https://gitee.com/api/v5/repos/***/***/blobs{/sha}", + "stargazers_url": "https://gitee.com/api/v5/repos/***/***/stargazers", + "contributors_url": "https://gitee.com/api/v5/repos/***/***/contributors", + "commits_url": "https://gitee.com/api/v5/repos/***/***/commits{/sha}", + "comments_url": "https://gitee.com/api/v5/repos/***/***/comments{/number}", + "issue_comment_url": "https://gitee.com/api/v5/repos/***/***/issues/comments{/number}", + "issues_url": "https://gitee.com/api/v5/repos/***/***/issues{/number}", + "pulls_url": "https://gitee.com/api/v5/repos/***/***/pulls{/number}", + "milestones_url": "https://gitee.com/api/v5/repos/***/***/milestones{/number}", + "notifications_url": "https://gitee.com/api/v5/repos/***/***/notifications{?since,all,participating}", + "labels_url": "https://gitee.com/api/v5/repos/***/***/labels{/name}", + "releases_url": "https://gitee.com/api/v5/repos/***/***/releases{/id}", + "recommend": false, + "gvp": false, + "homepage": null, + "language": null, + "forks_count": 0, + "stargazers_count": 0, + "watchers_count": 1, + "default_branch": null, + "open_issues_count": 1, + "has_issues": true, + "has_wiki": true, + "issue_comment": false, + "can_comment": true, + "pull_requests_enabled": true, + "has_page": false, + "license": null, + "outsourced": false, + "project_creator": "***", + "members": [ + "***" + ], + "pushed_at": null, + "created_at": "2023-11-16T22:03:27+08:00", + "updated_at": "2023-11-16T22:03:44+08:00", + "parent": null, + "paas": null, + "assignees_number": 1, + "testers_number": 1, + "assignee": [ + { + "id": 100001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" + } + ], + "testers": [ + { + "id": 100001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" + } + ], + "status": "开始", + "programs": [], + "enterprise": null, + "project_labels": [], + "issue_template_source": "project" + }, + "milestone": null, + "created_at": "2023-11-16T22:03:44+08:00", + "updated_at": "2024-01-12T11:31:23+08:00", + "plan_started_at": null, + "deadline": null, + "finished_at": null, + "scheduled_time": 0, + "comments": 720, + "priority": 0, + "issue_type": "任务", + "program": null, + "security_hole": false, + "issue_state": "待办的", + "branch": null, + "issue_type_detail": { + "id": 1, + "title": "任务", + "template": null, + "ident": "task", + "color": "#0086D6", + "is_system": true, + "created_at": "2017-09-01T03:09:12+08:00", + "updated_at": "2017-09-01T03:09:12+08:00" + }, + "issue_state_detail": { + "id": 1, + "title": "待办的", + "color": "#8c92a4", + "icon": "icon-task-state-21", + "command": null, + "serial": 1, + "created_at": "2017-09-01T03:09:13+08:00", + "updated_at": "2017-09-01T03:09:13+08:00" + } +} \ No newline at end of file diff --git a/src/__tests__/mock/json/mock-gitee-user.json b/src/__tests__/mock/json/mock-gitee-user.json new file mode 100644 index 0000000..8f0d7fe --- /dev/null +++ b/src/__tests__/mock/json/mock-gitee-user.json @@ -0,0 +1,31 @@ +{ + "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 +} \ No newline at end of file diff --git a/src/__tests__/mock/json/mock-github-user.json b/src/__tests__/mock/json/mock-github-user.json new file mode 100644 index 0000000..6568d3f --- /dev/null +++ b/src/__tests__/mock/json/mock-github-user.json @@ -0,0 +1,34 @@ +{ + "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" +} \ No newline at end of file diff --git a/src/__tests__/mock/json/mock-gitlab-user.json b/src/__tests__/mock/json/mock-gitlab-user.json new file mode 100644 index 0000000..9cf7e87 --- /dev/null +++ b/src/__tests__/mock/json/mock-gitlab-user.json @@ -0,0 +1,42 @@ +{ + "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": [] +} \ No newline at end of file diff --git a/src/__tests__/mock/mock-git-user.ts b/src/__tests__/mock/mock-git-user.ts new file mode 100644 index 0000000..698bead --- /dev/null +++ b/src/__tests__/mock/mock-git-user.ts @@ -0,0 +1,19 @@ +import { mock, readJSONSync } from "../helper/helper"; + +export function mockGiteeUser() { + mock.onGet('https://gitee.com/api/v5/user').reply(async () => { + return [200, readJSONSync('mock-gitee-user.json')]; + }); +} + +export function mockGithubUser() { + mock.onGet('https://api.github.com/user').reply(async () => { + return [200, readJSONSync('mock-github-user.json')]; + }); +} + +export function mockGitlabUser() { + mock.onGet('https://gitlab.com/api/v4/user').reply(async () => { + return [200, readJSONSync('mock-gitlab-user.json')] + }); +} \ No newline at end of file diff --git a/src/__tests__/mock/mock-gitee-api.ts b/src/__tests__/mock/mock-gitee-api.ts index b02ce01..3bfba7a 100644 --- a/src/__tests__/mock/mock-gitee-api.ts +++ b/src/__tests__/mock/mock-gitee-api.ts @@ -1,5 +1,5 @@ import dayjs from "dayjs"; -import { GITEE_NUMBER, GITEE_OWNER, GITEE_REPO, mock } from "../helper/helper"; +import { GITEE_NUMBER, GITEE_OWNER, GITEE_REPO, mock, readJSONSync } from "../helper/helper"; import jsonfile from 'jsonfile'; const filepath = 'src/__tests__/mock/json/gitee.json'; @@ -95,229 +95,6 @@ export async function mockGiteeDeleteById() { export async function mockGiteeDetail() { mock.onGet(new RegExp(`https://gitee.com/api/v5/repos/${GITEE_OWNER}/${GITEE_REPO}/issues/${GITEE_NUMBER}`)).reply(async (config) => { - return [200, { - "id": 100001, - "url": "https://gitee.com/api/v5/repos/***/***/issues/***", - "repository_url": "https://gitee.com/api/v5/repos/***/***", - "labels_url": "https://gitee.com/api/v5/repos/***/***/issues/***/labels", - "comments_url": "https://gitee.com/api/v5/repos/***/***/issues/***/comments", - "html_url": "https://gitee.com/***/***/issues/***", - "parent_url": null, - "number": "***", - "parent_id": 0, - "depth": 0, - "state": "open", - "title": "***", - "body": "test body", - "user": { - "id": 100001, - "login": "***", - "name": "***", - "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" - }, - "labels": [], - "assignee": null, - "collaborators": [], - "repository": { - "id": 100001, - "full_name": "***/***", - "human_name": "***/***", - "url": "https://gitee.com/api/v5/repos/***/***", - "namespace": { - "id": 100001, - "type": "personal", - "name": "***", - "path": "***", - "html_url": "https://gitee.com/***" - }, - "path": "***", - "name": "***", - "owner": { - "id": 100001, - "login": "***", - "name": "***", - "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" - }, - "assigner": { - "id": 100001, - "login": "***", - "name": "***", - "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" - }, - "description": "", - "private": true, - "public": false, - "internal": false, - "fork": false, - "html_url": "https://gitee.com/***/***.git", - "ssh_url": "git@gitee.com:***/***.git", - "forks_url": "https://gitee.com/api/v5/repos/***/***/forks", - "keys_url": "https://gitee.com/api/v5/repos/***/***/keys{/key_id}", - "collaborators_url": "https://gitee.com/api/v5/repos/***/***/collaborators{/collaborator}", - "hooks_url": "https://gitee.com/api/v5/repos/***/***/hooks", - "branches_url": "https://gitee.com/api/v5/repos/***/***/branches{/branch}", - "tags_url": "https://gitee.com/api/v5/repos/***/***/tags", - "blobs_url": "https://gitee.com/api/v5/repos/***/***/blobs{/sha}", - "stargazers_url": "https://gitee.com/api/v5/repos/***/***/stargazers", - "contributors_url": "https://gitee.com/api/v5/repos/***/***/contributors", - "commits_url": "https://gitee.com/api/v5/repos/***/***/commits{/sha}", - "comments_url": "https://gitee.com/api/v5/repos/***/***/comments{/number}", - "issue_comment_url": "https://gitee.com/api/v5/repos/***/***/issues/comments{/number}", - "issues_url": "https://gitee.com/api/v5/repos/***/***/issues{/number}", - "pulls_url": "https://gitee.com/api/v5/repos/***/***/pulls{/number}", - "milestones_url": "https://gitee.com/api/v5/repos/***/***/milestones{/number}", - "notifications_url": "https://gitee.com/api/v5/repos/***/***/notifications{?since,all,participating}", - "labels_url": "https://gitee.com/api/v5/repos/***/***/labels{/name}", - "releases_url": "https://gitee.com/api/v5/repos/***/***/releases{/id}", - "recommend": false, - "gvp": false, - "homepage": null, - "language": null, - "forks_count": 0, - "stargazers_count": 0, - "watchers_count": 1, - "default_branch": null, - "open_issues_count": 1, - "has_issues": true, - "has_wiki": true, - "issue_comment": false, - "can_comment": true, - "pull_requests_enabled": true, - "has_page": false, - "license": null, - "outsourced": false, - "project_creator": "***", - "members": [ - "***" - ], - "pushed_at": null, - "created_at": "2023-11-16T22:03:27+08:00", - "updated_at": "2023-11-16T22:03:44+08:00", - "parent": null, - "paas": null, - "assignees_number": 1, - "testers_number": 1, - "assignee": [ - { - "id": 100001, - "login": "***", - "name": "***", - "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" - } - ], - "testers": [ - { - "id": 100001, - "login": "***", - "name": "***", - "avatar_url": "https://foruda.gitee.com/avatar/***466/***59_***_***75.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" - } - ], - "status": "开始", - "programs": [], - "enterprise": null, - "project_labels": [], - "issue_template_source": "project" - }, - "milestone": null, - "created_at": "2023-11-16T22:03:44+08:00", - "updated_at": "2024-01-12T11:31:23+08:00", - "plan_started_at": null, - "deadline": null, - "finished_at": null, - "scheduled_time": 0, - "comments": 720, - "priority": 0, - "issue_type": "任务", - "program": null, - "security_hole": false, - "issue_state": "待办的", - "branch": null, - "issue_type_detail": { - "id": 1, - "title": "任务", - "template": null, - "ident": "task", - "color": "#0086D6", - "is_system": true, - "created_at": "2017-09-01T03:09:12+08:00", - "updated_at": "2017-09-01T03:09:12+08:00" - }, - "issue_state_detail": { - "id": 1, - "title": "待办的", - "color": "#8c92a4", - "icon": "icon-task-state-21", - "command": null, - "serial": 1, - "created_at": "2017-09-01T03:09:13+08:00", - "updated_at": "2017-09-01T03:09:13+08:00" - } - }]; + return [200, readJSONSync('mock-gitee-detail.json')]; }); } \ No newline at end of file diff --git a/src/__tests__/mock/mock-gitee-user.ts b/src/__tests__/mock/mock-gitee-user.ts deleted file mode 100644 index 49d7a59..0000000 --- a/src/__tests__/mock/mock-gitee-user.ts +++ /dev/null @@ -1,35 +0,0 @@ -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 - }); -} \ No newline at end of file diff --git a/src/__tests__/mock/mock-github-user.ts b/src/__tests__/mock/mock-github-user.ts deleted file mode 100644 index 9dd9cb3..0000000 --- a/src/__tests__/mock/mock-github-user.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { mock } from "../helper/helper"; - -export function mockGithubUser() { - mock.onGet('https://api.github.com/user').reply(200, { - "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" - }); -} \ No newline at end of file diff --git a/src/__tests__/mock/mock-gitlab-user.ts b/src/__tests__/mock/mock-gitlab-user.ts deleted file mode 100644 index 4946872..0000000 --- a/src/__tests__/mock/mock-gitlab-user.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { mock } from "../helper/helper"; - -export function mockGitlabUser() { - mock.onGet('https://gitlab.com/api/v4/user').reply(200, { - "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": [] - }); -} \ No newline at end of file