-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(di): remove unused DIContext.runInContext and emit methods
BREAKING CHANGE: DIContext.runInContext and DIContext.emit methods are removed. Use runInContext and $emit function instead.
- Loading branch information
Showing
12 changed files
with
86 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 16 additions & 35 deletions
51
packages/orm/mikro-orm/src/filters/OptimisticLockErrorFilter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,33 @@ | ||
import {OptimisticLockError} from "@mikro-orm/core"; | ||
import {Logger} from "@tsed/logger"; | ||
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"; | ||
|
||
describe("OptimisticLockErrorFilter", () => { | ||
const mockedLogger: Logger = mock<Logger>(); | ||
let optimisticLockErrorFilter!: OptimisticLockErrorFilter; | ||
|
||
beforeEach(() => { | ||
optimisticLockErrorFilter = new OptimisticLockErrorFilter(); | ||
|
||
return PlatformTest.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
reset(mockedLogger); | ||
|
||
return PlatformTest.reset(); | ||
}); | ||
beforeEach(() => PlatformTest.create()); | ||
afterEach(() => PlatformTest.reset()); | ||
|
||
describe("catch", () => { | ||
it("should set HTTP status to 409", () => { | ||
it("should set HTTP status to 409", async () => { | ||
const optimisticLockErrorFilter = await PlatformTest.invoke(OptimisticLockErrorFilter); | ||
|
||
// arrange | ||
const exception = OptimisticLockError.lockFailed("entity"); | ||
const response = PlatformTest.createResponse(); | ||
const request = PlatformTest.createRequest({ | ||
url: "/admin" | ||
}); | ||
const context = new PlatformContext({ | ||
event: { | ||
response, | ||
request | ||
}, | ||
id: "id", | ||
logger: instance(mockedLogger), | ||
maxStackSize: 0, | ||
injector: PlatformTest.injector | ||
}); | ||
const spiedResponse = spy(response); | ||
const context = PlatformTest.createRequestContext(); | ||
|
||
vi.spyOn(context.logger, "error").mockReturnThis(); | ||
|
||
// act | ||
optimisticLockErrorFilter.catch(exception, context); | ||
|
||
verify(mockedLogger.error(objectContaining({exception}))).once(); | ||
verify(spiedResponse.status(409)).once(); | ||
expect(context.logger.error).toHaveBeenCalledWith({ | ||
event: "MIKRO_ORM_OPTIMISTIC_LOCK_ERROR", | ||
error_name: exception.name, | ||
error_message: exception.message, | ||
stack: exception.stack | ||
}); | ||
expect(context.response.getBody()).toEqual("Update refused. The resource has changed on the server. Please try again later"); | ||
expect(context.response.statusCode).toEqual(409); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.