[tests][mediacontroller] tests for new sendCommand implementation. 51/211251/9
authorMichal Michalski <m.michalski2@partner.samsung.com>
Wed, 31 Jul 2019 11:00:36 +0000 (13:00 +0200)
committerMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 6 Aug 2019 08:30:34 +0000 (10:30 +0200)
This testcases define expected behavior of sendCommand() method
after implementation is changed.

[Verification] Tests are passing with working version of new implementation.

Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
Change-Id: I5923e45bb0ddc2013b1fe81951a3966413a3e4b6

src/mediacontroller/js/ut/test_custom_command.js [new file with mode: 0644]

diff --git a/src/mediacontroller/js/ut/test_custom_command.js b/src/mediacontroller/js/ut/test_custom_command.js
new file mode 100644 (file)
index 0000000..5ac7ba7
--- /dev/null
@@ -0,0 +1,128 @@
+mocha.setup('bdd');
+
+describe('sendCommand', function () {
+  var client = null, server = null, sinfo = null, commandListenerId = null;
+
+  before(function() {
+    server = tizen.mediacontroller.createServer();
+    client = tizen.mediacontroller.getClient();
+    server.updatePlaybackState('PLAY');
+    sinfo = client.getLatestServerInfo();
+  });
+
+  afterEach(function() {
+    server.removeCommandListener(commandListenerId);
+  });
+
+  it('should trigger command listener and success callback', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(Object.keys(data).length).to.equal(1);
+      chai.expect(data.key).to.equal("value");
+      return {"key": "response data"};
+    });
+
+    sinfo.sendCommand("myCommand", {key: "value"}, function(response) {
+       chai.expect(Object.keys(response).length).to.equal(1);
+       chai.expect(response.key).to.equal("response data");
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+
+  it('should accept tizen.Bundle data argument', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(Object.keys(data).length).to.equal(1);
+      chai.expect(data.key).to.equal("value");
+      return {"key": "response data"};
+    });
+
+    sinfo.sendCommand("myCommand", new tizen.Bundle({key: "value"}), function(response) {
+       chai.expect(Object.keys(response).length).to.equal(1);
+       chai.expect(response.key).to.equal("response data");
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+
+  it('should accept null data argument', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(data).to.equal(null);
+      return {"key": "response data"};
+    });
+
+    sinfo.sendCommand("myCommand", null, function(response) {
+       chai.expect(Object.keys(response).length).to.equal(1);
+       chai.expect(response.key).to.equal("response data");
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+
+  it('should accept RequestReply as a response', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(data).to.equal(null);
+      return new tizen.mediacontroller.RequestReply({"key": "response data"}, 10);
+    });
+
+    sinfo.sendCommand("myCommand", null, function(data, code) {
+       chai.expect(code).to.equal(10);
+       chai.expect(Object.keys(data).length).to.equal(1);
+       chai.expect(data.key).to.equal("response data");
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+
+  it('should accept RequestReply with null data as a response', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(data).to.equal(null);
+      return new tizen.mediacontroller.RequestReply(null, 10);
+    });
+
+    sinfo.sendCommand("myCommand", null, function(data, code) {
+       chai.expect(code).to.equal(10);
+       chai.expect(data).to.equal(null);
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+
+  it('should be okey to return nothing from command listener', function (done) {
+    commandListenerId = server.addCommandListener(function(client, command, data) {
+      chai.expect(command).to.equal("myCommand");
+      chai.expect(data).to.equal(null);
+    });
+
+    sinfo.sendCommand("myCommand", null, function(data, code) {
+       chai.expect(data).to.equal(null);
+       chai.expect(code).to.equal(0);
+       done();
+    }, function(error) {
+       done(new Error(error));
+    });
+  });
+});
+
+mocha.checkLeaks();
+mocha.run()
+    .on('pass', function(test) {
+        console.log(test.title + " OK");
+    })
+    .on('fail', function(test, err) {
+        console.error(test.title + " FAILED");
+        console.error(err);
+    })
+    .on('end', function() {
+        console.log('All done');
+    });
+