Skip to content

Commit

Permalink
Add tests for session
Browse files Browse the repository at this point in the history
  • Loading branch information
muzzammilshahid committed May 14, 2024
1 parent 805641d commit 06b051d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/session_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import "package:test/expect.dart";
import "package:test/scaffolding.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/exports.dart";
import "package:xconn/src/types.dart";

void main() {
var router = Router()..addRealm("realm1");

var serializer = JSONSerializer();
var clientSideBase = ClientSideLocalBaseSession(1, "realm1", "local", "local", serializer, router);
var serverSideBase = ServerSideLocalBaseSession(1, "realm1", "local", "local", serializer, other: clientSideBase);

router.attachClient(serverSideBase);

var session = Session(clientSideBase);

const procedureName = "io.xconn.test_procedure";
late Registration registration;
test("register a procedure", () async {
registration = await session.register(procedureName, (inv) {
print("Invocation: args=${inv.args}, kwargs=${inv.kwargs}, details=${inv.details}");
return Result(args: inv.args, kwargs: inv.kwargs, details: inv.details);
});

expect(registration, isA<Registration>());
});

test("call a procedure", () async {
var args = ["abc", 1];
var kwargs = {"foo": 1};

var result = await session.call(procedureName, args: args, kwargs: kwargs);
expect(result, isA<Result>());
expect(result.args, args);
expect(result.kwargs, kwargs);
expect(result.details, {});
});

test("unregister a procedure", () async {
await session.unregister(registration);
});

const topicName = "io.xconn.test_topic";
late Subscription subscription;
test("subscribe to a topic", () async {
subscription = await session.subscribe(topicName, (event) {
print("Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}");
});
expect(subscription, isA<Subscription>());
});

test("publish to a topic", () async {
await session.publish(topicName, args: ["abc"], kwargs: {"one": 1}, options: {"acknowledge": true});
});

test("unsubscribe from a topic", () async {
await session.unsubscribe(subscription);
});
}

0 comments on commit 06b051d

Please sign in to comment.