Skip to content

Commit

Permalink
Merge pull request #82 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
Dev c
  • Loading branch information
GuoXiCheng authored Jan 15, 2024
2 parents 3532288 + ee843f4 commit 4ebdc22
Show file tree
Hide file tree
Showing 20 changed files with 704 additions and 338 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
"!src/**/*.d.ts", // 排除 TypeScript 声明文件
"!src/__tests__/**/*.ts"
],
testMatch: ["<rootDir>/src/__tests__/fake/*.test.ts"],
testMatch: ["<rootDir>/src/__tests__/tests/*.test.ts"],
testPathIgnorePatterns: []
};
};
15 changes: 0 additions & 15 deletions jest.config.real.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"types": "dist/index.d.ts",
"scripts": {
"test": "jest --coverage",
"test:real": "jest --coverage --config=jest.config.real.js",
"prebuild": "rimraf ./dist",
"build": "rollup --config"
},
Expand Down
24 changes: 0 additions & 24 deletions src/__tests__/authenticate-gitee.test.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/__tests__/authenticate-github.test.ts

This file was deleted.

49 changes: 0 additions & 49 deletions src/__tests__/authenticate-gitlab.test.ts

This file was deleted.

37 changes: 28 additions & 9 deletions src/__tests__/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ import timezone from 'dayjs/plugin/timezone';
import MockAdapter from 'axios-mock-adapter';
import jsonfile from 'jsonfile';

export const mock = new MockAdapter(axios);
// export const mock = new MockAdapter(axios);

dayjs.extend(utc);
dayjs.extend(timezone);

// 设置默认时区
dayjs.tz.setDefault('Asia/Shanghai');

export const GITEE_NUMBER = process.env.TEST_GITEE_NUMBER || '1';

export const GITHUB_NUMBER = process.env.TEST_GITHUB_NUMBER as string;
export const GITHUB_NUMBER = process.env.TEST_GITHUB_NUMBER || '1';

export const GITLAB_NUMBER = process.env.TEST_GITLAB_NUMBER as string;
export const GITLAB_NUMBER = process.env.TEST_GITLAB_NUMBER || '1';

export const ENCRYPT_KEY = process.env.TEST_ENCRYPT_KEY || 'test-encrypt-key';

export const GITEE_OWNER = process.env.TEST_GITEE_OWNER || 'test-owner';

export const GITEE_REPO = process.env.TEST_GITEE_REPO || 'test-repo';

export const USE_API = process.env.USE_API === 'true' || false;

export const GITHUB_OWNER = process.env.TEST_GITHUB_OWNER || 'test-owner';

export const GITHUB_REPO = process.env.TEST_GITHUB_REPO || 'test-repo';

export const GITLAB_PROJECT_ID = process.env.TEST_GITLAB_PROJECT_ID || 'test-project-id';

export let mock: MockAdapter | null = null;
if (!USE_API) {
mock = new MockAdapter(axios);
}

export const giteeRequest = createRequest({
httpLib: 'axios',
httpClient: axios,
Expand All @@ -50,21 +61,29 @@ export const giteeRequest = createRequest({
export const githubRequest = createRequest({
httpLib: 'axios',
httpClient: axios,

accessToken: process.env.TEST_GITHUB_TOKEN as string,

platform: 'github',
owner: process.env.TEST_GITHUB_OWNER as string,
repo: process.env.TEST_GITHUB_REPO as string,
issueNumber: process.env.TEST_GITHUB_NUMBER as string
owner: GITHUB_OWNER,
repo: GITHUB_REPO,
issueNumber: GITHUB_NUMBER
});

export const gitlabRequest = createRequest({
httpLib: 'axios',
httpClient: axios,

accessToken: process.env.TEST_GITLAB_TOKEN as string,

platform: 'gitlab',
projectId: process.env.TEST_GITLAB_PROJECT_ID as string
projectId: GITLAB_PROJECT_ID
});

export function readJSONSync(filename: string) {
return jsonfile.readFileSync(`src/__tests__/mock/json/${filename}`);
}

export function writeJSONSync(filename: string, data: any) {
return jsonfile.writeFileSync(`src/__tests__/mock/json/${filename}`, data, { spaces: 2 });
}
61 changes: 61 additions & 0 deletions src/__tests__/mock/json/mock-github-detail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"url": "https://api.github.com/repos/***/***/issues/***",
"repository_url": "https://api.github.com/repos/***/***",
"labels_url": "https://api.github.com/repos/***/***/issues/***/labels{/name}",
"comments_url": "https://api.github.com/repos/***/***/issues/***/comments",
"events_url": "https://api.github.com/repos/***/***/issues/***/events",
"html_url": "https://github.com/***/***/issues/***",
"id": 1000001,
"node_id": "I_k***IxW",
"number": 0,
"title": "For ***** Test",
"user": {
"login": "***",
"id": 1000001,
"node_id": "MDQ*****DA5",
"avatar_url": "https://avatars.git*****tent.com/u/3*****9?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
},
"labels": [],
"state": "open",
"locked": false,
"assignee": null,
"assignees": [],
"milestone": null,
"comments": 0,
"created_at": "2023-11-21T07:10:21Z",
"updated_at": "2024-01-11T01:58:16Z",
"closed_at": null,
"author_association": "OWNER",
"active_lock_reason": null,
"body": "test for body",
"closed_by": null,
"reactions": {
"url": "https://api.github.com/repos/***/***/issues/***/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
},
"timeline_url": "https://api.github.com/repos/***/***/issues/***/timeline",
"performed_via_github_app": null,
"state_reason": null
}
64 changes: 64 additions & 0 deletions src/__tests__/mock/json/mock-gitlab-detail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"id": 100001,
"iid": 2,
"project_id": 100001,
"title": "For *** Test New",
"description": "test",
"state": "opened",
"created_at": "2024-01-02T02:27:57.658Z",
"updated_at": "2024-01-15T08:06:48.811Z",
"closed_at": null,
"closed_by": null,
"labels": [],
"milestone": null,
"assignees": [],
"author": {
"id": 100001,
"username": "***",
"name": "***",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/***/avatar.png",
"web_url": "https://gitlab.com/***"
},
"type": "ISSUE",
"assignee": null,
"user_notes_count": 1,
"merge_requests_count": 0,
"upvotes": 0,
"downvotes": 0,
"due_date": null,
"confidential": false,
"discussion_locked": null,
"issue_type": "issue",
"web_url": "https://gitlab.com/***/***/-/issues/2",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"blocking_issues_count": 0,
"has_tasks": true,
"task_status": "0 of 0 checklist items completed",
"_links": {
"self": "https://gitlab.com/api/v4/projects/***/issues/2",
"notes": "https://gitlab.com/api/v4/projects/***/issues/2/notes",
"award_emoji": "https://gitlab.com/api/v4/projects/***/issues/2/award_emoji",
"project": "https://gitlab.com/api/v4/projects/***",
"closed_as_duplicate_of": null
},
"references": {
"short": "#2",
"relative": "#2",
"full": "***/***#2"
},
"severity": "UNKNOWN",
"subscribed": true,
"moved_to_id": null,
"service_desk_reply_to": null
}
6 changes: 3 additions & 3 deletions src/__tests__/mock/mock-git-user.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { mock, readJSONSync } from "../helper/helper";

export function mockGiteeUser() {
mock.onGet('https://gitee.com/api/v5/user').reply(async () => {
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 () => {
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 () => {
mock?.onGet('https://gitlab.com/api/v4/user').reply(async () => {
return [200, readJSONSync('mock-gitlab-user.json')]
});
}
Loading

0 comments on commit 4ebdc22

Please sign in to comment.