-
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 #39 from GuoXiCheng/main
publish 1.0.15
- Loading branch information
Showing
38 changed files
with
679 additions
and
147 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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module.exports = { | ||
testTimeout: 30000, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
collectCoverageFrom: [ | ||
"src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件 | ||
"!src/**/*.d.ts", // 排除 TypeScript 声明文件 | ||
"!src/__tests__/**/*.ts" | ||
], | ||
testMatch: ["<rootDir>/src/__tests__/**/*.test.ts"] | ||
}; |
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,95 @@ | ||
import { StartTest } from "./helper/start-test"; | ||
|
||
describe('Test Authenticate Function', () => { | ||
test('Test Authenticate Gitee', async () => { | ||
const request = StartTest.createGiteeRequest(); | ||
const res = await request.authenticate(); | ||
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' | ||
]) | ||
}); | ||
|
||
test('Test Authenticate Github', async () => { | ||
const request = StartTest.createGithubRequest(); | ||
const res = await request.authenticate(); | ||
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' | ||
]); | ||
}); | ||
|
||
test('Test Authenticate Gitlab', async () => { | ||
const request = StartTest.createGitlabRequest(); | ||
const res = await request.authenticate(); | ||
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' | ||
]); | ||
}); | ||
}); |
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,45 @@ | ||
import axios from 'axios'; | ||
import 'dotenv/config'; | ||
import { createRequest } from '../..'; | ||
|
||
export class StartTest { | ||
constructor() { | ||
|
||
} | ||
|
||
static createGiteeRequest() { | ||
return createRequest({ | ||
requestType: 'axios', | ||
request: axios, | ||
accessToken: process.env.TEST_GITEE_TOKEN as string, | ||
storagePlatform: 'gitee', | ||
owner: process.env.TEST_GITEE_OWNER as string, | ||
repo: process.env.TEST_GITEE_REPO as string | ||
}); | ||
} | ||
|
||
static getGiteeIssueNumber() { | ||
return process.env.TEST_GITEE_NUMBER as string; | ||
} | ||
|
||
static createGithubRequest() { | ||
return createRequest({ | ||
requestType: 'axios', | ||
request: axios, | ||
accessToken: process.env.TEST_GITHUB_TOKEN as string, | ||
storagePlatform: 'github', | ||
owner: '', | ||
repo: '' | ||
}); | ||
} | ||
|
||
static createGitlabRequest() { | ||
return createRequest({ | ||
requestType: 'axios', | ||
request: axios, | ||
accessToken: process.env.TEST_GITLAB_TOKEN as string, | ||
storagePlatform: 'gitlab', | ||
projectId: '' | ||
}); | ||
} | ||
} |
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,5 @@ | ||
import { BaseModel } from "../.."; | ||
export interface UserModel extends BaseModel { | ||
name: string; | ||
age: number; | ||
} |
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,9 @@ | ||
import { GiteeStorage } from '../..'; | ||
import { StartTest } from './start-test'; | ||
import { UserModel } from './user-model'; | ||
|
||
export class UserStorage extends GiteeStorage<UserModel> { | ||
constructor() { | ||
super(StartTest.createGiteeRequest(), StartTest.getGiteeIssueNumber()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { UserStorage } from "./helper/user-storage"; | ||
|
||
describe('Test User Storage', () => { | ||
const userStorage = new UserStorage(); | ||
|
||
test('Test deleteAll User', async () => { | ||
await userStorage.deleteAll(); | ||
const detail = await userStorage.find(); | ||
expect(detail.length).toEqual(0); | ||
}); | ||
|
||
test('Test create & User & findById User', async () => { | ||
await userStorage.create({ | ||
name: 'test-user', | ||
age: 18 | ||
}); | ||
const findResult = await userStorage.find(); | ||
expect(findResult.length).toEqual(1); | ||
|
||
const findByIdResult = await userStorage.findById(findResult[0].id); | ||
expect(findByIdResult).toEqual(findResult[0]); | ||
}); | ||
}); |
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,16 @@ | ||
export enum StoragePlatform { | ||
gitee = "gitee", | ||
github = "github", | ||
gitlab = "gitlab" | ||
} | ||
|
||
export enum RequestType { | ||
axios = "axios", | ||
wx = "wx" | ||
} | ||
|
||
export enum OfficialUrl { | ||
gitee = "https://gitee.com", | ||
github = "https://api.github.com", | ||
gitlab = "https://gitlab.com" | ||
} |
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,16 +1,4 @@ | ||
import {TinyRequestInstance} from "./request-lib"; | ||
export enum StoragePlatform { | ||
gitee = "gitee", | ||
github = "github", | ||
gitlab = "gitlab" | ||
} | ||
|
||
export enum RequestLib { | ||
axios = "axios", | ||
wx = "wx" | ||
} | ||
|
||
export type StoragePlatformType = keyof typeof StoragePlatform; | ||
export type RequestLibType = keyof typeof RequestLib; | ||
export {TinyRequestInstance}; | ||
import {createRequest} from "./request-lib/create-request"; | ||
import { BaseModel, GiteeStorage } from "./storage-lib"; | ||
export {createRequest, BaseModel, GiteeStorage}; | ||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AxiosInstance } from "axios"; | ||
|
||
export type AxiosOptions = { | ||
requestType: 'axios'; | ||
request: AxiosInstance; | ||
} |
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,55 @@ | ||
import { AxiosInstance } from 'axios'; | ||
import { BaseRequest } from '../base/base-request'; | ||
import { RequestOptions } from '../base/request-options'; | ||
|
||
export class AxiosRequest extends BaseRequest { | ||
private axios: AxiosInstance; | ||
constructor( | ||
protected options: RequestOptions | ||
) { | ||
super(options); | ||
this.axios = options.request as AxiosInstance; | ||
} | ||
|
||
async get<T>(url: string): Promise<T> { | ||
return new Promise((resolve, reject) => { | ||
this.axios.get<T>(url, { | ||
headers: { | ||
'Authorization': `Bearer ${this.accessToken}` | ||
} | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
async post<T>(url: string, data: any): Promise<T> { | ||
return new Promise((resolve, reject) => { | ||
this.axios.post<T>(url, data, { | ||
headers: { | ||
'Authorization': `Bearer ${this.accessToken}` | ||
} | ||
}).then((res) => { | ||
resolve(res.data); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
async delete<T>(url: string): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
this.axios.delete<T>(url, { | ||
headers: { | ||
'Authorization': `Bearer ${this.accessToken}` | ||
} | ||
}).then(() => { | ||
resolve(); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.