Skip to content

Commit

Permalink
feat(platform-http): the PlatformTest is now exportable from @tsed/pl…
Browse files Browse the repository at this point in the history
…atform-http/testing
  • Loading branch information
Romakita committed Oct 12, 2024
1 parent 1096919 commit 4fcf708
Show file tree
Hide file tree
Showing 366 changed files with 511 additions and 403 deletions.
2 changes: 1 addition & 1 deletion PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Example to use your feature and to improve the documentation after merging your PR:
```typescript
import {} from "@tsed/common";
import {} from "@tsed/platform-http";
```
-->
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tsed/platform-views": ["../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/common/index.ts"],
"@tsed/ajv": ["../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../specs/swagger/src/index.ts"],
Expand Down
6 changes: 2 additions & 4 deletions packages/di/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ The `@Injectable()` attaches the metadata, thereby Ts.ED knows that this class i
Now we have the service class already done, let's use it inside a controller:

```typescript
import {Controller, Post, Body, Get} from "@tsed/common";
import {Controller} from "@tsed/di";
import {Post, Body, Get} from "@tsed/schema";
import {CalendarsService} from "./CalendarsService.js";
import {Calendar} from "./models/Calendar.js";

Expand All @@ -111,9 +112,6 @@ export class CalendarCtrl {
}
```

> Note: Controller isn't a part of `@tsed/di`. `@Controller` decorator is exposed by `@tsed/common` package because it's a specific provider
> used by the Ts.ED framework. Ts.ED DI allow you to define your own Provider and decorator.
Finally, we can load the injector and use:

```typescript
Expand Down
2 changes: 1 addition & 1 deletion packages/di/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@tsed/platform-views": ["../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/common/index.ts"],
"@tsed/ajv": ["../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../specs/swagger/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/engines/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tsed/platform-views": ["../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../platform/platform-http/src/common/index.ts"],
"@tsed/ajv": ["../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../specs/swagger/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/apollo/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ npm install --save-dev apollo-server-testing
Now, we can configure the Ts.ED server by importing `@tsed/apollo` in your Server:

```typescript
import {Configuration} from "@tsed/common";
import {Configuration} from "@tsed/di";
import "@tsed/apollo";

@Configuration({
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/apollo/src/services/ApolloService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {ApolloServer, ApolloServerPlugin} from "@apollo/server";
import {catchAsyncError} from "@tsed/core";
import {Configuration, Constant, InjectContext, Module, runInContext} from "@tsed/di";
import {Logger} from "@tsed/logger";
import {PlatformApplication, PlatformContext, PlatformTest} from "@tsed/platform-http";
import {PlatformApplication, PlatformContext} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {HTTPDataSource} from "apollo-datasource-http";

import {APOLLO_CONTEXT} from "../constants/constants.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/apollo/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql/graphql-ws/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ npm install --save @tsed/graphql-ws graphql-ws
Now, we can configure the Ts.ED server by importing `@tsed/gr` in your Server:

```typescript
import {Configuration} from "@tsed/common";
import {Configuration} from "@tsed/di";
import "@tsed/apollo";

@Configuration({
Expand All @@ -63,7 +63,8 @@ export class Server {}
ApolloService let you retrieve an instance of ApolloServer.

```typescript
import {Injectable, AfterRoutesInit} from "@tsed/common";
import {Injectable} from "@tsed/di";
import {AfterRoutesInit} from "@tsed/platform-http";
import {graphQLService} from "@tsed/apollo";
import {ApolloServer} from "@apollo/server";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "@tsed/platform-express";

import {PlatformExpress} from "@tsed/platform-express";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import SuperTest from "supertest";

import {Server} from "./app/Server.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/typegraphql/test/typegraphql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@tsed/graphql-ws";
import {ApolloService} from "@tsed/apollo";
import {runInContext} from "@tsed/di";
import {PlatformExpress} from "@tsed/platform-express";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {gql} from "graphql-tag";

import {Server} from "./app/Server.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/typegraphql/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
3 changes: 2 additions & 1 deletion packages/orm/adapters-redis/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/src/adapters/FileSyncAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {faker} from "@faker-js/faker";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {Property} from "@tsed/schema";

import {Adapter} from "../domain/Adapter.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/src/adapters/LowDbAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {faker} from "@faker-js/faker";
import {deserialize} from "@tsed/json-mapper";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {Format, Name, Property} from "@tsed/schema";

import {Adapter, Adapters, MemoryAdapter} from "../../src/index.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/src/adapters/MemoryAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {faker} from "@faker-js/faker";
import {deserialize} from "@tsed/json-mapper";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {Format, getJsonSchema, Name, Property} from "@tsed/schema";

import {Adapter} from "../domain/Adapter.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/src/decorators/indexed.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from "@tsed/di";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {Property} from "@tsed/schema";

import {MemoryAdapter} from "../adapters/MemoryAdapter.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/adapters/src/decorators/injectAdapter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Injectable} from "@tsed/di";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {Name, Property} from "@tsed/schema";

import {MemoryAdapter} from "../adapters/MemoryAdapter.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {DiscriminatorKey, DiscriminatorValue, Property, Required} from "@tsed/schema";

import {Adapter, Adapters, FileSyncAdapter} from "../src/index.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/orm/adapters/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
3 changes: 2 additions & 1 deletion packages/orm/ioredis/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
23 changes: 16 additions & 7 deletions packages/orm/mikro-orm/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ The `mikroOrm` options accepts the same configuration object as `init()` from th
`@Orm` decorator lets you retrieve an instance of MikroORM.

```typescript
import {Injectable, AfterRoutesInit} from "@tsed/common";
import {Injectable} from "@tsed/di";
import {AfterRoutesInit} from "@tsed/platform-http";
import {Orm} from "@tsed/mikro-orm";
import {MikroORM} from "@mikro-orm/core";

Expand Down Expand Up @@ -146,7 +147,8 @@ export class MyService {
`@EntityManager` and `@Em` decorators lets you retrieve an instance of EntityManager.

```typescript
import {Injectable, AfterRoutesInit} from "@tsed/common";
import {Injectable} from "@tsed/di";
import {AfterRoutesInit} from "@tsed/platform-http";
import {Em} from "@tsed/mikro-orm";
import {EntityManager} from "@mikro-orm/mysql"; // Import EntityManager from your driver package or `@mikro-orm/knex`

Expand All @@ -167,7 +169,8 @@ export class UsersService {
It's also possible to inject Entity manager by his context name:

```typescript
import {Injectable, AfterRoutesInit} from "@tsed/common";
import {Injectable} from "@tsed/di";
import {AfterRoutesInit} from "@tsed/platform-http";
import {Em} from "@tsed/mikro-orm";
import {EntityManager} from "@mikro-orm/mysql"; // Import EntityManager from your driver package or `@mikro-orm/knex`

Expand All @@ -190,7 +193,7 @@ export class UsersService {
To begin, we need to define an Entity MikroORM like this and use Ts.ED Decorator to define the JSON Schema.

```typescript
import {Property, MaxLength, Required} from "@tsed/common";
import {Property, MaxLength, Required} from "@tsed/schema";
import {Entity, Property, PrimaryKey, Property as Column} from "@mikro-orm/core";

@Entity()
Expand Down Expand Up @@ -223,7 +226,9 @@ Now, the model is correctly defined and can be used with a [Controller](https://
We can use this model with a Controller like that:

```typescript
import {Controller, Post, BodyParams, Inject, Post, Get} from "@tsed/common";
import {Controller, Inject} from "@tsed/common";
import {BodyParamst} from "@tsed/platform-params";
import {Post, Post, Get} from "@tsed/schema";

@Controller("/users")
export class UsersCtrl {
Expand Down Expand Up @@ -251,7 +256,9 @@ We can use the `@Transactional()` decorator, which will register a new request c
inside the context.

```typescript
import {Controller, Post, BodyParams, Inject, Get} from "@tsed/common";
import {BodyParamst} from "@tsed/platform-params";
import {Post, Post, Get} from "@tsed/schema";
import {Controller, Inject} from "@tsed/di";
import {Transactional} from "@tsed/mikro-orm";

@Controller("/users")
Expand Down Expand Up @@ -354,7 +361,9 @@ export class ExponentialBackoff implements RetryStrategy {
Once a retry strategy is implemented, you can enable an automatic retry mechanism using the `@Transactional` decorator like that:

```typescript
import {Controller, Post, BodyParams, Inject, Get} from "@tsed/common";
import {BodyParamst} from "@tsed/platform-params";
import {Post, Post, Get} from "@tsed/schema";
import {Controller, Inject} from "@tsed/di";
import {Transactional} from "@tsed/mikro-orm";

@Controller("/users")
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/mikro-orm/src/MikroOrmModule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {EntityManager, EventSubscriber, MikroORM, Options} from "@mikro-orm/core";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {anyOfClass, anything, deepEqual, instance, mock, reset, verify, when} from "ts-mockito";

import {Subscriber} from "./decorators/subscriber.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {OptimisticLockError} from "@mikro-orm/core";
import {Logger} from "@tsed/logger";
import {PlatformContext, PlatformTest} from "@tsed/platform-http";
import {PlatformContext} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {instance, mock, objectContaining, reset, spy, verify} from "ts-mockito";

import {OptimisticLockErrorFilter} from "./OptimisticLockErrorFilter.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/mikro-orm/test/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {EntityManager, MikroORM} from "@mikro-orm/core";
import {defineConfig} from "@mikro-orm/mongodb";
import {Logger} from "@tsed/logger";
import {PlatformTest} from "@tsed/platform-http";
import {PlatformTest} from "@tsed/platform-http/testing";
import {TestContainersMongo} from "@tsed/testcontainers-mongo";
import {anyOfClass, anything, reset, spy, verify} from "ts-mockito";

Expand Down
3 changes: 2 additions & 1 deletion packages/orm/mikro-orm/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@tsed/platform-views": ["../../platform/platform-views/src/index.ts"],
"@tsed/normalize-path": ["../../utils/normalize-path/src/index.ts"],
"@tsed/components-scan": ["../../third-parties/components-scan/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/index.ts"],
"@tsed/platform-http": ["../../platform/platform-http/src/common/index.ts"],
"@tsed/platform-http/testing": ["../../platform/platform-http/src/testing/index.ts"],
"@tsed/ajv": ["../../specs/ajv/src/index.ts"],
"@tsed/platform-cache": ["../../platform/platform-cache/src/index.ts"],
"@tsed/swagger": ["../../specs/swagger/src/index.ts"],
Expand Down
20 changes: 10 additions & 10 deletions packages/orm/mongoose/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ npm install --save-dev @types/mongoose
Then import `@tsed/mongoose` in your Server:

```typescript
import {Configuration} from "@tsed/common";
import {Configuration} from "@tsed/di";
import "@tsed/mongoose"; // import mongoose ts.ed module

@Configuration({
Expand All @@ -76,7 +76,7 @@ The mongoose module of Ts.ED Mongoose allows to configure several basic connecti
Here is an example configuration:

```typescript
import {Configuration} from "@tsed/common";
import {Configuration} from "@tsed/di";
import "@tsed/mongoose"; // import mongoose ts.ed module

@Configuration({
Expand All @@ -98,10 +98,10 @@ export class Server {}

## MongooseService

MongooseService let you to retrieve an instance of Mongoose.Connection.
MongooseService let you retrieve an instance of Mongoose.Connection.

```typescript
import {Service} from "@tsed/common";
import {Service} from "@tsed/di";
import {MongooseService} from "@tsed/mongoose";

@Service()
Expand All @@ -118,12 +118,12 @@ export class MyService {
## Declaring a Model

By default, Ts.ED mongoose will reuse the metadata stored by the decorators dedicated
to describe a JsonSchema. This decorators come from the `@tsed/common` package.
to describe a JsonSchema. These decorators come from the `@tsed/schema` package.

Here a model example:

```typescript
import {Minimum, Maximum, MaxLength, MinLength, Enum, Pattern, Required, CollectionOf} from "@tsed/common";
import {Minimum, Maximum, MaxLength, MinLength, Enum, Pattern, Required, CollectionOf} from "@tsed/schema";
import {Model, Unique, Indexed, Ref, ObjectID} from "@tsed/mongoose";

enum Categories {
Expand Down Expand Up @@ -170,7 +170,7 @@ export class MyModel {
## Inject model

```typescript
import {Service, Inject} from "@tsed/common";
import {Service, Inject} from "@tsed/di";
import {MongooseModel} from "@tsed/mongoose";
import {MyModel} from "./models/MyModel.js";

Expand Down Expand Up @@ -210,7 +210,7 @@ We can simply attach a `@PreHook` decorator to your model class and
define the hook function like you normally would in Mongoose.

```typescript
import {Required} from "@tsed/common";
import {Required} from "@tsed/schema";
import {PreHook, Model, ObjectID} from "@tsed/mongoose";

@Model()
Expand Down Expand Up @@ -249,7 +249,7 @@ We can simply attach a `@PostHook` decorator to your model class and
define the hook function like you normally would in Mongoose.

```typescript
import {ObjectID, Required} from "@tsed/common";
import {ObjectID, Required} from "@tsed/schema";
import {PostHook, Model} from "@tsed/mongoose";

@Model()
Expand Down Expand Up @@ -287,7 +287,7 @@ Just like the regular `schema.plugin()` call, the decorator accepts 1 or 2 param
Multiple `plugin` decorator can be used for a single model class.

```typescript
import {Service} from "@tsed/common";
import {Service} from "@tsed/di";
import {MongoosePlugin, Model, MongooseModel} from "@tsed/mongoose";
import * as findOrCreate from 'mongoose-findorcreate';

Expand Down
Loading

0 comments on commit 4fcf708

Please sign in to comment.