-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix async connection method in RpgClientEngine
- Loading branch information
RSamaium
committed
Dec 5, 2023
1 parent
8af2fff
commit 1a289fa
Showing
9 changed files
with
109 additions
and
19 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {_beforeEach} from './beforeEach' | ||
import { RpgMap, RpgModule, RpgPlayer, RpgServer, RpgServerEngine } from '@rpgjs/server' | ||
import { clear, testing } from '@rpgjs/testing' | ||
import { test, afterEach, expect, vi, describe } from 'vitest' | ||
|
||
test('Test onStart Hook', async () => { | ||
const onStart = vi.fn() | ||
|
||
@RpgModule<RpgServer>({ | ||
engine: { | ||
onStart | ||
} | ||
}) | ||
class RpgServerModule {} | ||
|
||
await _beforeEach([{ | ||
server: RpgServerModule | ||
}]) | ||
|
||
expect(onStart).toHaveBeenCalled() | ||
expect(onStart).toHaveBeenCalledWith(expect.any(RpgServerEngine)) | ||
}) | ||
|
||
test('Test onStep Hook', async () => { | ||
const onStep = vi.fn() | ||
|
||
@RpgModule<RpgServer>({ | ||
engine: { | ||
onStep | ||
} | ||
}) | ||
class RpgServerModule {} | ||
|
||
await _beforeEach([{ | ||
server: RpgServerModule | ||
}]) | ||
|
||
expect(onStep).toHaveBeenCalled() | ||
expect(onStep).toHaveBeenCalledWith(expect.any(RpgServerEngine)) | ||
}) | ||
|
||
describe('Test auth Hook', () => { | ||
|
||
async function createAuthTest(auth) { | ||
|
||
@RpgModule<RpgServer>({ | ||
engine: { | ||
auth | ||
} | ||
}) | ||
class RpgServerModule {} | ||
|
||
const { player } = await _beforeEach([{ | ||
server: RpgServerModule | ||
}]) | ||
|
||
expect(auth).toHaveBeenCalled() | ||
expect(auth).toHaveBeenCalledWith(expect.any(RpgServerEngine), expect.anything()) | ||
expect(auth).toHaveReturnedWith('test') | ||
expect(player.id).toBe('test') | ||
} | ||
|
||
test('Test auth Hook', async () => { | ||
const auth = vi.fn().mockReturnValue('test') | ||
await createAuthTest(auth) | ||
}) | ||
|
||
test('Test auth Hook with Promise', async () => { | ||
const auth = vi.fn().mockResolvedValue('test') | ||
await createAuthTest(auth) | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
clear() | ||
}) |