Skip to content

Commit

Permalink
Merge pull request #11 from muzzammilshahid/helpers-tests
Browse files Browse the repository at this point in the history
Add tests for helpers
  • Loading branch information
muzzammilshahid authored May 9, 2024
2 parents 87a7a71 + 953708d commit 9c653c2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 40 deletions.
82 changes: 82 additions & 0 deletions test/helpers_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import "dart:typed_data";

import "package:test/test.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/src/helpers.dart";

class TestSerializer implements Serializer {
@override
Uint8List serialize(final Message message) {
return Uint8List.fromList("".codeUnits);
}

@override
Message deserialize(final Object message) {
return Hello("realm", {}, "", []);
}
}

void main() {
test("getSubProtocol", () {
// with json Serializer
var jsonProtocol = getSubProtocol(JSONSerializer());
expect(jsonProtocol, jsonSubProtocol);

// with cbor Serializer
var cborProtocol = getSubProtocol(CBORSerializer());
expect(cborProtocol, cborSubProtocol);

// with msgpack Serializer
var msgpackProtocol = getSubProtocol(MsgPackSerializer());
expect(msgpackProtocol, msgpackSubProtocol);

// with invalid Serializer
expect(() => getSubProtocol(TestSerializer()), throwsArgumentError);
});

test("getSerializer", () {
// with json subProtocol
var jsonSerializer = getSerializer(jsonSubProtocol);
expect(jsonSerializer, isA<JSONSerializer>());

// null should also return jsonSerializer
var jsonSerializer1 = getSerializer(null);
expect(jsonSerializer1, isA<JSONSerializer>());

// with cbor subProtocol
var cborSerializer = getSerializer(cborSubProtocol);
expect(cborSerializer, isA<CBORSerializer>());

// with msgpack subProtocol
var msgpackSerializer = getSerializer(msgpackSubProtocol);
expect(msgpackSerializer, isA<MsgPackSerializer>());

// with invalid subProtocol
expect(() => getSerializer("abc"), throwsException);
});

test("wampErrorString", () {
// with no args or kwargs
final error = Error(Register.id, 1, "wamp.error.no_such_procedure");
var errString = wampErrorString(error);
expect(errString, "wamp.error.no_such_procedure");

// with args only
final errorArgs = Error(Register.id, 1, "wamp.error.no_such_procedure", args: [1, "two"]);
var errArgsString = wampErrorString(errorArgs);
expect(errArgsString, "wamp.error.no_such_procedure: 1, two");

// with kwargs only
final errorKwArgs = Error(Register.id, 1, "wamp.error.no_such_procedure", kwargs: {"key": "value"});
var errKwArgsString = wampErrorString(errorKwArgs);
expect(errKwArgsString, "wamp.error.no_such_procedure: key=value");

// with args and kwargs
final errorArgsKwArgs =
Error(Register.id, 1, "wamp.error.no_such_procedure", args: [1, "two"], kwargs: {"key": "value"});
var errArgsKwArgsString = wampErrorString(errorArgsKwArgs);
expect(errArgsKwArgsString, "wamp.error.no_such_procedure: 1, two: key=value");
});
}
40 changes: 0 additions & 40 deletions test/wamp_session_joiner_test.dart

This file was deleted.

0 comments on commit 9c653c2

Please sign in to comment.