Skip to content

Commit

Permalink
Merge pull request #27 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
add storage-lib
  • Loading branch information
GuoXiCheng authored Dec 4, 2023
2 parents 4f1ae11 + 1a5edd2 commit aa10f64
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 22 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = {
"!src/**/*.d.ts", // 排除 TypeScript 声明文件
"!src/__tests__/**/*.ts"
],
testMatch: ["<rootDir>/src/__tests__/**/*.test.ts"]
};
14 changes: 14 additions & 0 deletions src/__tests__/helper/start-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios';
import 'dotenv/config';
import { TinyRequestInstance } from '../../request-lib';
import { RequestLib } from '../../enums';

export class StartTest {
constructor() {

}

getRequest() {
return TinyRequestInstance(RequestLib.axios, axios, process.env.GITEE_TOKEN as string);
}
}
8 changes: 8 additions & 0 deletions src/__tests__/helper/user-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { StartTest } from './start-test';
import { GiteeStorage } from '../../storage-lib/gitee-storage';

export class UserStorage extends GiteeStorage {
constructor() {
super(new StartTest().getRequest());
}
}
3 changes: 0 additions & 3 deletions src/__tests__/index.test.ts

This file was deleted.

8 changes: 3 additions & 5 deletions src/__tests__/request-lib.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dotenv/config';
import { TinyRequestInstance } from '../request-lib';
import { RequestLib } from '..';
import axios from 'axios';
import { StartTest } from './helper/start-test';


test('Test TinyRequestInstance', async () => {
const instance = TinyRequestInstance(RequestLib.axios, axios, process.env.GITEE_TOKEN as string);
const detail = await instance.get(process.env.GITEE_GET_ALL_URL as string);
const request = new StartTest().getRequest();
const detail = await request.get(process.env.GITEE_GET_ALL_URL as string);
expect(detail.length).toBeGreaterThan(0);
}, 30000);
7 changes: 7 additions & 0 deletions src/__tests__/storage-lib.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { UserStorage } from "./helper/user-storage";

test('Test Storage Lib', async () => {
const userStorage = new UserStorage();
const detail: any[] = await userStorage.findAll();
expect(detail.length).toBeGreaterThan(0);
}, 30000);
10 changes: 10 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum StoragePlatform {
gitee = "gitee",
github = "github",
gitlab = "gitlab"
}

export enum RequestLib {
axios = "axios",
wx = "wx"
}
13 changes: 0 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
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};

3 changes: 2 additions & 1 deletion src/request-lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AxiosInstance } from "axios";
import { RequestLib, RequestLibType } from "..";
import { AxiosRequestFactory, RequestInstance, WxRequestFactory } from "./request-factories";
import { WxInstance } from "./interfaces";
import { RequestLibType } from "../types";
import { RequestLib } from "../enums";

export function TinyRequestInstance(requestLibType: RequestLibType, instance: RequestInstance, accessToken: string) {
switch (requestLibType) {
Expand Down
17 changes: 17 additions & 0 deletions src/storage-lib/gitee-storage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { TinyRequest } from "../request-lib/interfaces";
import { TinyStorage } from "./interfaces";

export class GiteeStorage implements TinyStorage {
protected baseUrl = "https://gitee.com";
constructor(private requestInstance: TinyRequest) { }

async findOne(): Promise<void> {
this.requestInstance.get("");
}

async findAll(): Promise<any> {
const url = `${this.baseUrl}/api/v5/repos/guoxicheng/tiny-crud/issues/I8H4X2/comments`;
return this.requestInstance.get(url);
}

}
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions src/storage-lib/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TinyStorage {
findOne(): void;
findAll(): void;
}
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { RequestLib, StoragePlatform } from "./enums";

export type StoragePlatformType = keyof typeof StoragePlatform;
export type RequestLibType = keyof typeof RequestLib;

0 comments on commit aa10f64

Please sign in to comment.