Skip to content

Commit

Permalink
Merge pull request #73 from GuoXiCheng/main
Browse files Browse the repository at this point in the history
publish 1.0.22
  • Loading branch information
GuoXiCheng authored Jan 10, 2024
2 parents df99ddf + aae9245 commit 5f90391
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 102 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testTimeout: 60000,
testTimeout: 120000,
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverageFrom: [
Expand Down
11 changes: 9 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-crud",
"version": "1.0.21",
"version": "1.0.22",
"description": "",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
Expand All @@ -25,6 +25,7 @@
"@rollup/plugin-typescript": "^11.1.5",
"@types/crypto-js": "^4.2.1",
"@types/jest": "^29.5.9",
"@types/wechat-miniprogram": "^3.4.7",
"axios": "^1.6.2",
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10",
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/user-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe('Test User Storage', () => {
age: 36
}];

// beforeAll(async () => {
// await User.deleteAll();
// });
beforeAll(async () => {
await User.deleteAll();
});

test('Test find User', async () => {
const detail = await User.find();
Expand Down
88 changes: 0 additions & 88 deletions src/__tests__/wx-request.test.ts

This file was deleted.

88 changes: 88 additions & 0 deletions src/__tests__/wx-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// import { createRequest } from '../request-lib';

// const wx = {
// request: jest.fn()
// };

// const request = createRequest({
// httpLib: 'wx',
// httpClient: wx,
// platform: 'gitee',
// owner: 'test-owner',
// repo: 'test-repo',
// accessToken: 'test-token'
// });

// describe('Test Wx Request', () => {
// test('wx get success', async () => {
// wx.request.mockImplementation(({ success }) => {
// success({data: 'success'});
// });
// const result = await request.get('test-url', { order: 'desc'});
// expect(result).toEqual('success');
// expect(wx.request).toHaveBeenCalledWith({
// 'fail': expect.any(Function),
// 'data': {
// 'order': 'desc'
// },
// 'header': {
// 'Authorization': 'Bearer test-token'
// },
// 'method': 'GET',
// 'success': expect.any(Function),
// 'url': 'test-url'
// });
// });

// test('wx get fail', async () => {
// wx.request.mockImplementation(({ fail }) => {
// fail('fail');
// });
// try {
// await request.get('test-url');
// } catch (error) {
// expect(error).toEqual('fail');
// }
// });

// test('wx post success', async () => {
// wx.request.mockImplementation(({ success }) => {
// success({data: 'success'});
// });
// const result = await request.post('test-url', 'test-body');
// expect(result).toEqual('success');
// expect(wx.request).toHaveBeenCalledWith({
// 'fail': expect.any(Function),
// 'data': {
// 'body': 'test-body'
// },
// 'header': {
// 'Authorization': 'Bearer test-token'
// },
// 'method': 'POST',
// 'success': expect.any(Function),
// 'url': 'test-url'
// });
// });

// test('wx patch success', async () => {
// wx.request.mockImplementation(({ success }) => {
// success({data: 'success'});
// });
// const result = await request.patch('test-url', 'test-body');
// expect(result).toEqual('success');
// expect(wx.request).toHaveBeenCalledWith({
// 'fail': expect.any(Function),
// 'data': {
// 'body': 'test-body'
// },
// 'header': {
// 'Authorization': 'Bearer test-token',
// 'X-HTTP-Method-Override': 'PATCH'
// },
// 'method': 'POST',
// 'success': expect.any(Function),
// 'url': 'test-url'
// });
// });
// });
4 changes: 1 addition & 3 deletions src/request-lib/wx/wx-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { WxInstance } from "./wx-interface";

export type WxOptions = {
httpLib: 'wx';
httpClient: WxInstance
httpClient: WechatMiniprogram.Wx
}
8 changes: 4 additions & 4 deletions src/request-lib/wx/wx-request.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { BaseRequest } from '../base/base-request';
import { RequestMethods } from '../base/request-methods';
import { RequestOptions } from '../base/request-options';
import { WxInstance, WxRequestOptions } from './wx-interface';

export class WxRequest extends BaseRequest {
private wx: WxInstance;
private wx: WechatMiniprogram.Wx;
constructor(
public options: RequestOptions
) {
super(options);
this.wx = options.httpClient as WxInstance;
this.wx = options.httpClient as WechatMiniprogram.Wx;
}

protected async sendRequest<T>(method: RequestMethods, url: string, body?: string, params?: any): Promise<T> {
return new Promise((resolve, reject) => {
const options: WxRequestOptions = {
const options: WechatMiniprogram.RequestOption = {
url,
method,
...(body && { data: { body } }),
Expand All @@ -33,6 +32,7 @@ export class WxRequest extends BaseRequest {
// wx不支持 PATCH,特别处理 PATCH 方法
if (method === 'PATCH') {
options.method = 'POST';
options.header = options.header || {};
options.header['X-HTTP-Method-Override'] = 'PATCH';
}

Expand Down

0 comments on commit 5f90391

Please sign in to comment.