Skip to content

Commit

Permalink
feat: 🎸 tipset find
Browse files Browse the repository at this point in the history
  • Loading branch information
waynewyang committed Jan 3, 2024
1 parent 5e0c5d7 commit f35694e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 105 deletions.
6 changes: 2 additions & 4 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
********************************************************************************/

import { Module } from '@nestjs/common';
import { SampleController } from './sample/sample.controller';
import { SampleService } from './sample/sample.service';
import { TipsetController } from './tipset/tipset.controller';
import { TipsetService } from './tipset/tipset.service';
import { BackgroundTaskService } from './backgroundTask/provider/backgroundTask.service';
Expand All @@ -30,7 +28,7 @@ import { BackgroundTaskService } from './backgroundTask/provider/backgroundTask.
*/
@Module({
imports: [],
controllers: [SampleController, TipsetController],
providers: [SampleService, TipsetService, BackgroundTaskService],
controllers: [TipsetController],
providers: [TipsetService, BackgroundTaskService],
})
export class AppModule {}
45 changes: 0 additions & 45 deletions src/sample/sample.controller.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/sample/sample.service.ts

This file was deleted.

22 changes: 16 additions & 6 deletions src/tipset/tipset.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* limitations under the respective licenses.
********************************************************************************/

import { Controller, Get } from '@nestjs/common';
import { Controller, Post, Body } from '@nestjs/common';
import { TipsetService } from './tipset.service';
// import { QueryFilter } from '@unipackage/datastore';
import { QueryFilter } from '@unipackage/datastore';
import { Tipset } from '@unipackage/filecoin';
import { ValueFields, Result } from '@unipackage/utils';

Expand All @@ -37,11 +37,21 @@ export class TipsetController {

/**
* Handles GET requests for root-level resources with an identifier.
* @param param - Request parameters.
* @param queryFilter - Request parameters.
* @returns A string representing the response.
* @example
* {
* "conditions": [
* {
* "Height": { "$gt": 1213437, "$lt": 1213439 }
* }
* ]
* }
*/
@Get()
async find(): Promise<Result<ValueFields<Tipset>[]>> {
return await this.tipsetService.find({});
@Post()
async find(
@Body() queryFilter: QueryFilter<ValueFields<Tipset>>,
): Promise<Result<ValueFields<Tipset>[]>> {
return await this.tipsetService.find(queryFilter);
}
}
10 changes: 5 additions & 5 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ describe('AppController (e2e)', () => {
await app.close();
});

it('/ (GET)', () => {
it('/tipset (POST)', () => {
return request(app.getHttpServer())
.get('/:4')
.expect(200)
.expect('Hello World!');
});
.post('/tipset')
.send({ conditions: [{ Height: { $gt: 1213437, $lt: 1213439 } }] })
.expect(201);
}, 30000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,40 @@
* See the MIT License or the Apache License for the specific language governing permissions and
* limitations under the respective licenses.
********************************************************************************/
import { calibrationBgTask } from '../../src/config/backgroundTask';
import { delay } from '@unipackage/utils';

import { Test, TestingModule } from '@nestjs/testing';
import { SampleController } from '../../src/sample/sample.controller';
import { SampleService } from '../../src/sample/sample.service';
import { TipsetController } from '../../src/tipset/tipset.controller';
import { TipsetService } from '../../src/tipset/tipset.service';

describe('SampleController', () => {
let sampleController: SampleController;
let tipsetController: TipsetController;

beforeAll(() => {
calibrationBgTask.start();
});

afterAll(() => {
calibrationBgTask.stop();
});

beforeEach(async () => {
const root: TestingModule = await Test.createTestingModule({
controllers: [SampleController],
providers: [SampleService],
controllers: [TipsetController],
providers: [TipsetService],
}).compile();

sampleController = root.get<SampleController>(SampleController);
tipsetController = root.get<TipsetController>(TipsetController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(sampleController.getHello(1)).toBe('Hello World!');
});
describe('tipset query', () => {
it('should ok', async () => {
await delay(20000);
const res = await tipsetController.find({
conditions: [{ Height: { $gt: 1213437, $lt: 1213439 } }],
});
expect(res.ok).toBe(true);
}, 500000);
});
});

0 comments on commit f35694e

Please sign in to comment.