-
Notifications
You must be signed in to change notification settings - Fork 1
/
spawn-abstract.test.ts
67 lines (53 loc) · 2.02 KB
/
spawn-abstract.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ChangeUserNameStatus, ChangeUserNameResponse, ChangeUserName } from './protos/user_test'
import spawn, { payloadFor, SpawnSystem } from '../src/spawn'
import { createUnnamedActor } from './stubs/actors'
import { describe, beforeAll, afterAll, test, expect } from 'bun:test'
describe('testing spawn unnamed actor', () => {
let system: SpawnSystem
beforeAll(async () => {
system = spawn.createSystem('SpawnSysTest')
createUnnamedActor(system)
const registered = await system.register()
if (registered.status?.message != 'Accepted') throw new Error('Failed to register system')
})
afterAll(async () => {
await system.destroy()
})
test('settting new name for a named actor', async () => {
await spawn.spawnActor('namedActorTest_01', {
system: 'SpawnSysTest',
actorRef: 'unnamedActorTest'
})
const expected = ChangeUserNameResponse.create({
status: ChangeUserNameStatus.OK,
newName: 'novo_nome'
})
const payload = payloadFor(ChangeUserName, ChangeUserName.create({ newName: 'novo_nome' }))
const action = 'setName'
const newNameResponse = await spawn.invoke('namedActorTest_01', {
action,
payload,
response: ChangeUserNameResponse,
system: 'SpawnSysTest'
})
expect(newNameResponse.newName).toBe(expected.newName)
expect(newNameResponse.status).toBe(expected.status)
})
test('settting new name for a named actor invoking directly', async () => {
const expected = ChangeUserNameResponse.create({
status: ChangeUserNameStatus.OK,
newName: 'novo_nome'
})
const payload = payloadFor(ChangeUserName, ChangeUserName.create({ newName: 'novo_nome' }))
const action = 'setName'
const newNameResponse = await spawn.invoke('namedActorTest_02', {
action,
payload,
response: ChangeUserNameResponse,
ref: 'unnamedActorTest',
system: 'SpawnSysTest'
})
expect(newNameResponse.newName).toBe(expected.newName)
expect(newNameResponse.status).toBe(expected.status)
})
})