Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
undyingwraith committed Nov 9, 2023
1 parent a067cf6 commit ea646e0
Show file tree
Hide file tree
Showing 46 changed files with 844 additions and 86 deletions.
8 changes: 8 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsAllocationsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {AllocationsOptions} from '../options';
import {AllocationResult} from '../results';

export interface IIpfsAllocationsApi {
list(options: AllocationsOptions): Promise<AllocationResult>;

get(cid: string): void;
}
30 changes: 30 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsClusterApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {PeerInfo, VersionResult} from '../results';
import {AddOptions} from '../options';
import {IIpfsPeersApi} from './IIpfsPeersApi';
import {IIpfsPinsApi} from './IIpfsPinsApi';
import {IIpfsAllocationsApi} from './IIpfsAllocationsApi';

export interface IIpfsClusterApi {
readonly peers: IIpfsPeersApi;
readonly pins: IIpfsPinsApi;
readonly allocations: IIpfsAllocationsApi;

/**
* Cluster peer information
* @return {Promise<PeerInfo>}
*/
id(): Promise<PeerInfo>;

/**
* Cluster version
*/
version(): Promise<VersionResult>;

/**
* Add content to the cluster.
* @param data
* @param {AddOptions} options
* @return {Promise<void>}
*/
add(data: any, options: AddOptions): Promise<void>;
}
14 changes: 14 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsPeersApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {PeerListResult, RemovePeerResult} from './IpfsPeersApi';

export interface IIpfsPeersApi {
/**
* Cluster peers.
*/
list(): Promise<PeerListResult>;

/**
* Remove a peer.
* @param {string} peerId
*/
remove(peerId: string): Promise<RemovePeerResult>;
}
18 changes: 18 additions & 0 deletions ipfs-cluster-api/src/api/IIpfsPinsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {PinOptions, PinStatusOptions} from '../options';

export interface IIpfsPinsApi {
/**
* Local status of all tracked CIDs.
*/
list(): void;

status(cid: string, options?: PinStatusOptions): any;

add(cid: string, options: PinOptions): any;

remove(cid: string): Promise<any>;

recover(cid?: string): void;

update(from: string, to: string, options: PinOptions): Promise<void>;
}
3 changes: 2 additions & 1 deletion ipfs-cluster-api/src/api/IpfsAllocationsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {AxiosInstance} from 'axios';
import {AllocationsOptions} from '../options';
import {AllocationResult} from '../results';
import {mapOptions} from '../utils';
import {IIpfsAllocationsApi} from './IIpfsAllocationsApi';

export class IpfsAllocationsApi {
export class IpfsAllocationsApi implements IIpfsAllocationsApi {
constructor(private readonly api: AxiosInstance) {
}

Expand Down
18 changes: 9 additions & 9 deletions ipfs-cluster-api/src/api/IpfsClusterApi.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import axios, {AxiosInstance} from 'axios';
import {AddOptions} from '../options';
import {PeerInfo} from '../results';
import {VersionResult} from '../results';
import {PeerInfo, VersionResult} from '../results';
import {IpfsAllocationsApi} from './IpfsAllocationsApi';
import {IpfsPeersApi} from './IpfsPeersApi';
import {IpfsPinsApi} from './IpfsPinsApi';
import {IIpfsClusterApi} from './IIpfsClusterApi';

export class IpfsClusterApi {
export class IpfsClusterApi implements IIpfsClusterApi {
/**
* Create a new Cluster interface.
* @param {string} apiUrl API Url of the cluster
Expand All @@ -19,15 +19,15 @@ export class IpfsClusterApi {
* Cluster peer information
* @return {Promise<PeerInfo>}
*/
public id(): Promise<PeerInfo> {
id(): Promise<PeerInfo> {
return this.api.get('/id')
.then(r => r.data);
}

/**
* Cluster version
*/
public version(): Promise<VersionResult> {
version(): Promise<VersionResult> {
return this.api.get('/version')
.then(r => r.data);
}
Expand All @@ -36,15 +36,15 @@ export class IpfsClusterApi {
* Peers API
* @return {IpfsPeersApi}
*/
public get peers(): IpfsPeersApi {
get peers(): IpfsPeersApi {
return new IpfsPeersApi(this.api);
}

/**
* Pins API
* @return {IpfsPinsApi}
*/
public get pins(): IpfsPinsApi {
get pins(): IpfsPinsApi {
return new IpfsPinsApi(this.api);
}

Expand All @@ -54,11 +54,11 @@ export class IpfsClusterApi {
* @param {AddOptions} options
* @return {Promise<void>}
*/
public add(data: any, options: AddOptions): Promise<void> {
add(data: any, options: AddOptions): Promise<void> {
return Promise.reject();
}

public get allocations(): IpfsAllocationsApi {
get allocations(): IpfsAllocationsApi {
return new IpfsAllocationsApi(this.api);
}

Expand Down
7 changes: 4 additions & 3 deletions ipfs-cluster-api/src/api/IpfsPeersApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {AxiosInstance} from 'axios';
import {PeerInfo} from '../results';
import {IIpfsPeersApi} from './IIpfsPeersApi';

export type PeerListResult = PeerInfo[]

export type RemovePeerResult = unknown

export class IpfsPeersApi {
export class IpfsPeersApi implements IIpfsPeersApi {
constructor(private readonly api: AxiosInstance) {
}

/**
* Cluster peers.
*/
public list(): Promise<PeerListResult> {
list(): Promise<PeerListResult> {
return this.api.get('/peers')
.then(r => r.data);
}
Expand All @@ -21,7 +22,7 @@ export class IpfsPeersApi {
* Remove a peer.
* @param {string} peerId
*/
public remove(peerId: string): Promise<RemovePeerResult> {
remove(peerId: string): Promise<RemovePeerResult> {
return this.api.delete(`/peers/${peerId}`)
.then(r => r.data);
}
Expand Down
18 changes: 9 additions & 9 deletions ipfs-cluster-api/src/api/IpfsPinsApi.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {AxiosInstance} from 'axios';
import {PinOptions} from '../options';
import {PinStatusOptions} from '../options';
import {PinOptions, PinStatusOptions} from '../options';
import {mapOptions} from '../utils';
import {IIpfsPinsApi} from './IIpfsPinsApi';

export class IpfsPinsApi {
export class IpfsPinsApi implements IIpfsPinsApi {
constructor(private readonly api: AxiosInstance) {
}

/**
* Local status of all tracked CIDs.
*/
public list() {
list() {

}

public status(cid: string, options?: PinStatusOptions) {
status(cid: string, options?: PinStatusOptions) {
return this.api.get(`/pins/${cid}?${mapOptions(options)}`).then(r => r.data);
}

public add(cid: string, options: PinOptions) {
add(cid: string, options: PinOptions) {
return this.api.post(`/pins/ipfs/${cid}?${mapOptions(options)}`);
}

public remove(cid: string): Promise<any> {
remove(cid: string): Promise<any> {
return this.api.delete(`/pins/${cid}`).then(r => r.data);
}

public recover(cid?: string) {
recover(cid?: string) {

}

public update(from: string, to: string, options: PinOptions) {
update(from: string, to: string, options: PinOptions) {
return this.api.post(`/pins/ipfs/${to}?mode=recursive&pin-update=${from}&${mapOptions(options)}`).then(r => {
});
}
Expand Down
4 changes: 4 additions & 0 deletions ipfs-cluster-api/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export type {IpfsPeersApi} from './IpfsPeersApi';
export type {IIpfsPeersApi} from './IIpfsPeersApi';
export {IpfsClusterApi} from './IpfsClusterApi';
export type {IIpfsClusterApi} from './IIpfsClusterApi';
export type {IpfsAllocationsApi} from './IpfsAllocationsApi';
export type {IIpfsAllocationsApi} from './IIpfsAllocationsApi';
export type {IpfsPinsApi} from './IpfsPinsApi';
export type {IIpfsPinsApi} from './IIpfsPinsApi';
7 changes: 5 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
preset: 'ts-jest',
testEnvironment: 'jsdom',
coveragePathIgnorePatterns: [
"<rootDir>/testing/"
],
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"watch": "yarn workspaces foreach -Api run watch",
"build": "yarn workspaces foreach -At run build",
"test": "jest",
"test-coverage": "jest --ci --coverage --testLocationInResults"
"test-coverage": "jest --ci --coverage"
},
"devDependencies": {
"jest": "^29.7.0",
Expand Down
4 changes: 0 additions & 4 deletions testing/context/MockIpfsClusterContext.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions testing/context/MockIpfsContext.tsx

This file was deleted.

8 changes: 8 additions & 0 deletions testing/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"name": "testing",
"packageManager": "yarn@3.2.4",
"jsnext": "src/index.ts",
"typings": "src/index.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"kubo-rpc-client": "^3.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"webui": "workspace:^"
},
"scripts": {
"build": "tsc"
},
"devDependencies": {
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
Expand Down
3 changes: 3 additions & 0 deletions testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {MockIpfsClusterApi} from './mock/MockIpfsClusterApi'
export {MockIpfsClient} from './mock/MockIpfsClient'
export {MemoryConfigurationStore} from './service/MemoryConfigurationStore'
11 changes: 11 additions & 0 deletions testing/src/mock/MockIpfsAllocationsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {AllocationResult, AllocationsOptions, IIpfsAllocationsApi} from 'ipfs-cluster-api';

export class MockIpfsAllocationsApi implements IIpfsAllocationsApi {
get(cid: string): void {
}

list(options: AllocationsOptions): Promise<AllocationResult> {
return Promise.resolve([]);
}

}
Loading

0 comments on commit ea646e0

Please sign in to comment.