Skip to content

Commit

Permalink
Merge pull request #77 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
Dev c
  • Loading branch information
GuoXiCheng authored Jan 11, 2024
2 parents cb98e8c + 414ab8d commit de51b7c
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: npm install

- name: Run Jest tests
run: npm run test
run: npm run test:real
env:
TEST_GITEE_TOKEN: ${{ secrets.TEST_GITEE_TOKEN }}
TEST_GITEE_OWNER: ${{ secrets.TEST_GITEE_OWNER }}
Expand Down
20 changes: 20 additions & 0 deletions jest.config.fake.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
testTimeout: 120000,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: [
"src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件
"!src/**/*.d.ts", // 排除 TypeScript 声明文件
"!src/__tests__/**/*.ts"
],
testMatch: ["<rootDir>/src/__tests__/**/*.test.ts"],
testPathIgnorePatterns: [
"src/__tests__/authenticate-gitee.test.ts",
"src/__tests__/authenticate-github.test.ts",
"src/__tests__/authenticate-gitlab.test.ts",
"src/__tests__/book-repository.test.ts",
"src/__tests__/chat-repository.test.ts",
"src/__tests__/user-repository.test.ts",
"src/__tests__/wx-request.test.ts"
]
};
26 changes: 15 additions & 11 deletions jest.config.js → jest.config.real.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module.exports = {
testTimeout: 120000,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: [
"src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件
"!src/**/*.d.ts", // 排除 TypeScript 声明文件
"!src/__tests__/**/*.ts"
],
testMatch: ["<rootDir>/src/__tests__/**/*.test.ts"]
};
module.exports = {
testTimeout: 120000,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: [
"src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件
"!src/**/*.d.ts", // 排除 TypeScript 声明文件
"!src/__tests__/**/*.ts"
],
testMatch: ["<rootDir>/src/__tests__/**/*.test.ts"],
testPathIgnorePatterns: [
"src/__tests__/fake-authenticate-gitee.test.ts",
"src/__tests__/wx-request.test.ts"
]
};
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"module": "dist/bundle.esm.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jest --coverage",
"test:fake": "jest --coverage --config=jest.config.fake.js",
"test:real": "jest --coverage --config=jest.config.real.js",
"prebuild": "rimraf ./dist",
"build": "rollup --config"
},
Expand All @@ -27,6 +28,7 @@
"@types/jest": "^29.5.9",
"@types/wechat-miniprogram": "^3.4.7",
"axios": "^1.6.2",
"axios-mock-adapter": "^1.22.0",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10",
"dotenv": "^16.3.1",
Expand Down
37 changes: 37 additions & 0 deletions src/__tests__/fake-authenticate-gitee.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { giteeRequest } from './helper/helper';
describe('Test Use Fake Authenticate Gitee', () => {
test('Test Authenticate Gitee', async () => {
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
});
});
});
38 changes: 38 additions & 0 deletions src/__tests__/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

// const mock = new MockAdapter(axios);

// mock.onGet('https://fake-gitee/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
// });

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

Expand All @@ -23,10 +57,14 @@ export const TEST_ENCRYPT_KEY = process.env.TEST_ENCRYPT_KEY as string;
export const giteeRequest = createRequest({
httpLib: 'axios',
httpClient: axios,

baseURL: undefined,
accessToken: process.env.TEST_GITEE_TOKEN as string,

platform: 'gitee',
owner: process.env.TEST_GITEE_OWNER as string,
repo: process.env.TEST_GITEE_REPO as string,

useEncrypt: true,
encryptFn: (data: string) => {
return CryptoJS.AES.encrypt(data, TEST_ENCRYPT_KEY).toString();
Expand Down
File renamed without changes.
7 changes: 1 addition & 6 deletions src/repository-lib/base/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,7 @@ export abstract class BaseRepository<T extends BaseModel> {
async deleteAll(): Promise<void> {
const findUrl = this.getRoute(RouteType.find);
const findResult = await this.request.get<BaseComment[]>(findUrl);
console.log(findResult);
for (const item of findResult) {
const deleteResult = await this.deleteById(item.id);
console.log(deleteResult);
}
// await Promise.all(findResult.map((item) => this.deleteById(item.id)));
await Promise.all(findResult.map((item) => this.deleteById(item.id)));
}

// 序列化: 将对象转换为字符串
Expand Down

0 comments on commit de51b7c

Please sign in to comment.