/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @fileoverview Miscellaneous features * 1) opensocial.requestSendMessage: * - 1.1 requestSenMessage OWNER MISC010 * - 1.2 requestSenMessage VIEWER MISC020 * - 1.3 requestSenMessage OWNER_FRIENDS MISC030 * - 1.4 requestSenMessage VIEWER_FRIENDS MISC040 * - 1.5 requestSenMessage otherID MISC050 * - 1.6 requestSenMessage erroHandling MISC060 * * 2) opensocial.requestShareApp: * - 2.1 requestShareApp OWNER MISC070 * - 2.2 requestShareApp VIEWER MISC080 * - 2.3 requestShareApp OWNER_FRIENDS MISC090 * - 2.4 requestShareApp VIEWER_FRIENDS MISC100 * - 2.5 requestShareApp otherID MISC110 * - 2.6 requestShareApp errorHandling MISC120 * * 3) opensocial.Collection * - 3.1 newFetchPeopleRequest * * 4) requestPermission * - 4.1 requestPermission - VIEWER */ function MiscSuite() { this.name = 'Miscellaneous'; this.id = 'MISC'; this.tests = [ /************************************ * 1) opensocial.requestSendMessage: ************************************/ { name: 'Message Object Creation', id: 'MISC000', priority: Test.PRIORITY.P0, run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var title = 'Test requestSendMessage (Owner)'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = title ; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); var messageValue = message.getField(opensocial.Message.Field.TITLE); Helper.addSubResult(result, 'Message.Title', Assert.assertEquals, messageValue, title); messageValue = message.getField(opensocial.Message.Field.BODY); Helper.addSubResult(result, 'Message.Body', Assert.assertEquals, messageValue, body); messageValue = message.getField(opensocial.Message.Field.TYPE); Helper.addSubResult(result, 'Message.Type', Assert.assertEquals, messageValue, opensocial.Message.Type.PUBLIC_MESSAGE) callback(result); } }, { name: 'requestSendMessage - OWNER', id: 'MISC010', priority: Test.PRIORITY.P0, description: 'Tests if the container can send the message to the OWNER.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Owner)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage(opensocial.DataRequest.PersonId.OWNER, message, function(dataResponse){ Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Verify dataResponse for error', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, { name: 'requestSendMessage - VIEWER', id: 'MISC020', priority: Test.PRIORITY.P0, description: 'Tests if the container can send the message to the VIEWER.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Viewer'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Viewer)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage(opensocial.DataRequest.PersonId.VIEWER, message, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Verify dataResponse for error', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, { name: 'requestSendMessage - OWNER_FRIENDS', id: 'MISC030', priority: Test.PRIORITY.P0, description: 'Tests if the container can send the message to' + ' OWNER_FRIENDS.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner Friends'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Owner Friends)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage( opensocial.DataRequest.PersonId.OWNER_FRIENDS, message, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Verify dataResponse for error', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, { name: 'requestSendMessage - VIEWER_FRIENDS', id: 'MISC040', priority: Test.PRIORITY.P0, description: 'Tests if the container can send the message to' + ' VIEWER_FRIENDS.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Viewer Friends'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Viewer Friends)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage( opensocial.DataRequest.PersonId.VIEWER_FRIENDS, message, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Verify dataResponse for error', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, { name: 'requestSendMessage - Specific ID', id: 'MISC050', priority: Test.PRIORITY.P0, description: 'Tests if the container can send the message to user with' + 'specific ID.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Owner)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); var friendId = MiscSuite.getFirstFriendId(); result.setResult(Assert.assertNotNull(friendId), friendId, 'Not Null'); if (friendId) { opensocial.requestSendMessage(friendId, message, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Verify dataResponse for error', Assert.assertFalse, dataResponse.hadError(), 'false'); }); } callback(result); } }, { name: 'requestSendMessage - OWNER - Params is not Defined', id: 'MISC060', description: 'Tests if request can be sent to the OWNER' + ' without any paramters .', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var message = opensocial.newMessage(body); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage( opensocial.DataRequest.PersonId.OWNER, message, function(dataResponse) { Helper.addSubResult(result, 'Error expected', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, { name: 'requestSendMessage - OWNER - Body is not Defined', id: 'MISC061', description: 'Tests if request can be sent to the OWNER without body.', tags: ['notImplementedYet'], run: function(context, callback, result) { var body = undefined; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Viewer Friends)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage( opensocial.DataRequest.PersonId.OWNER, message, function(dataResponse) { Helper.addSubResult(result, 'Error expected', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, { name: 'requestSendMessage - OWNER - Message is undefined', id: 'MISC062', description: 'Tests if request can be sent to the OWNER with an ' + 'undefined message', tags: ['notImplementedYet'], run: function(context, callback, result) { var message = undefined; opensocial.requestSendMessage( opensocial.DataRequest.PersonId.OWNER, message, function(dataResponse) { result.setResult(Assert.assertTrue(dataResponse.hadError()), dataResponse.hadError(), 'Error expected'); }); callback(result); } }, { name: 'requestSendMessage - OWNER - Message is null', id: 'MISC063', description: 'Tests if request can be sent to the OWNER with ' + 'message as null .', tags: ['notImplementedYet'], run: function(context, callback, result) { var message = null; opensocial.requestSendMessage(opensocial.DataRequest.PersonId.OWNER, message, function(dataResponse) { Helper.addSubResult(result, 'Error expected', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, { name: 'requestSendMessage - OWNER - recipients Spec is null', id: 'MISC064', description: 'Tests if request can be sent to the OWNER with recipients' + ' spec as null .', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Owner)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage(null, message, function(dataResponse) { Helper.addSubResult(result, 'Error expected', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, { name: 'requestSendMessage - OWNER - recipients Spec is empty', id: 'MISC065', description: 'Tests if request can be sent to the OWNER with recipients' + ' spec as empty.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var body = 'This is a message sent [' + today + '] to Owner'; var params = {} params[opensocial.Message.Field.BODY] = body; params[opensocial.Message.Field.TITLE] = 'Test requestSendMessage (Owner)'; params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PUBLIC_MESSAGE; var message = opensocial.newMessage(body, params); Helper.addSubResult(result, 'Message Creation', Assert.assertDefined, message, 'Message Defined'); opensocial.requestSendMessage([], message, function(dataResponse) { Helper.addSubResult(result, 'Error expected', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, /********************************************** * 2) opensocial.requestShareApp: MISC000 * - 2.1 requestShareApp OWNER MISC100 * - 2.2 requestShareApp VIEWER MISC200 * - 2.3 requestShareApp OWNER_FRIENDS MISC300 * - 2.4 requestShareApp VIEWER_FRIENDS MISC400 * - 2.5 requestShareApp otherID MISC500 * - 2.6 requestShareApp errorHandling MISC600 ************************************************/ /* - 2.1 requestShareApp OWNER MISC070 */ { name: 'requestShareApp - OWNER', id: 'MISC070', priority: Test.PRIORITY.P0, description: 'Tests if request can be sent to the container to ' + 'share a gadget to the OWNER', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp(opensocial.DataRequest.PersonId.OWNER, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Succeess', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, /* - 2.2 requestShareApp VIEWER MISC080 */ { name: 'requestShareApp - VIEWER', id: 'MISC080', priority: Test.PRIORITY.P0, description: 'Tests if request can be sent to the container to ' + 'share a gadget to the VIEWER', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp(opensocial.DataRequest.PersonId.VIEWER, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Succeess', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, /* - 2.3 requestShareApp OWNER_FRIENDS MISC090 */ { name: 'requestShareApp - OWNER_FRIENDS', id: 'MISC090', priority: Test.PRIORITY.P0, description: 'Tests if request can be sent to the container to ' + 'share a gadget to the OWNER_FRIENDS', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp( opensocial.DataRequest.PersonId.OWNER_FRIENDS, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Succeess', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, /* - 2.4 requestShareApp VIEWER_FRIENDS MISC100 */ { name: 'requestShareApp - VIEWER_FRIENDS', id: 'MISC100', priority: Test.PRIORITY.P0, description: 'Tests if request can be sent to the container to ' + 'share a gadget to the VIEWER_FRIENDS', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp( opensocial.DataRequest.PersonId.VIEWER_FRIENDS, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Succeess', Assert.assertFalse, dataResponse.hadError(), 'false'); }); callback(result); } }, /* - 2.5 requestShareApp Specific ID MISC110 */ { name: 'requestShareApp - Specific ID', id: 'MISC110', priority: Test.PRIORITY.P0, description: 'Tests if request can be sent to the container to ' + 'share a gadget to a specific ID.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; var friendID = MiscellaneousSuite.getFirstFriendId(); result.setResult(Assert.assertNotNull(friendID), friendID, 'not null friendID'); if (friendID) { opensocial.requestShareApp( opensocial.DataRequest.PersonId.VIEWER_FRIENDS, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Succeess', Assert.assertFalse, dataResponse.hadError(), 'false'); }); } callback(result); } }, /* - 2.6 requestShareApp Null MISC120 */ { name: 'requestShareApp - NULL', id: 'MISC120', description: 'Tests if request can be sent to the container to ' + 'share a gadget to a null value', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp( null, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Failed', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, /* - 2.6 requestShareApp Empty MISC121 */ { name: 'requestShareApp - Empty', id: 'MISC121', description: 'Tests if request can be sent to the container to ' + 'share a gadget to an empty space', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp( '', reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Failed', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, /* - 2.6 requestShareApp Undefined MISC122 */ { name: 'requestShareApp - Undefined', id: 'MISC122', description: 'Tests if request can be sent to the container to ' + 'share a gadget to an undefined value.', tags: ['notImplementedYet'], run: function(context, callback, result) { var today = new Date(); var reason = 'Share this app [' + today + ']'; opensocial.requestShareApp( undefined, reason, function(dataResponse) { Helper.addSubResult(result, 'DataResponse defined', Assert.assertDefined, dataResponse, 'Should be Object'); Helper.addSubResult(result, 'Share App Request Failed', Assert.assertTrue, dataResponse.hadError(), 'true'); }); callback(result); } }, /****************************************************** * 3 newFetchPeopleRequest - Misc - Collections *******************************************************/ { name: 'Collection - Collection.each(Person)', id: 'MSC300', run: function(context, callback, result) { var req = opensocial.newDataRequest(); req.add(req.newFetchPeopleRequest('OWNER_FRIENDS'), 'ownerFriends'); req.send(function(dataResponse) { Assert.assertDataResponseHadError(dataResponse, result, ['ownerFriends'], false); if (!dataResponse.hadError()) { var perCollection = dataResponse.get('ownerFriends').getData(); var atLeastOneDoesntExist = false; perCollection.each(function(person) { if (perCollection.getById(person.getId()) == null) { atLeastOneDoesntExist = true; } }); Helper.addSubResult(result, 'Collection.each()', Assert.assertFalse, atLeastOneDoesntExist, 'False. All persons must exist') } callback(result); }); } }, { name: 'Collection - size() and totalSize()', id: 'MSC301', run: function(context, callback, result) { var req = opensocial.newDataRequest(); req.add(req.newFetchPeopleRequest('OWNER_FRIENDS'), 'ownerFriends'); req.send(function(dataResponse) { Assert.assertDataResponseHadError(dataResponse, result, ['ownerFriends'], false); if (!dataResponse.hadError()) { var actual = dataResponse.get('ownerFriends').getData(); var friends = context.getExpectedViewer()['__friends__']; var outcome; var smallLength = friends ? (friends.length <= 20) : undefined; var largeLength = friends ? (friends.length > 20) : undefined; if (smallLength || largeLength) { if (smallLength) { Helper.addSubResult(result, 'size() & totalSize()', Assert.assertEquals, actual.getTotalSize(), actual.size()); } else { Helper.addSubResult(result, 'size() & totalSize()', Assert.assertNotEquals, actual.getTotalSize(), actual.size()); } } else { outcome = undefined; Helper.addSubResult(result, 'size() & totalSize()', Assert.assertTrue, true, 'Total:' + actual.getTotalSize() + ' & ' + 'Size:'+ actual.size()); } if (friends) { Helper.addSubResult(result, 'Collection.size()', Assert.assertEquals, actual.size(), friends.length); } else { Helper.addSubResult(result, 'Collection.size()', Assert.assertTrue, actual.size() >= 0, actual.size()); } } callback(result); }); } }, { name: 'Collection - getOffset()', id: 'MSC302', run: function(context, callback, result) { var req = opensocial.newDataRequest(); var params = {}; params[opensocial.DataRequest.PeopleRequestFields.FIRST] = 1; req.add(req.newFetchPeopleRequest('OWNER_FRIENDS', params), 'ownerFriends'); req.send(function(dataResponse) { Assert.assertDataResponseHadError(dataResponse, result, ['ownerFriends'], false); if (!dataResponse.hadError()) { var dataCollection = dataResponse.get('ownerFriends').getData(); Helper.addSubResult(result, 'Collection - getOffset>0', Assert.assertTrue, dataCollection.getOffset() > 0, 'getOffset > 0'); } callback(result); }); } }, { name: 'Collection - getOffset() huge offset', id: 'MSC303', run: function(context, callback, result) { var req = opensocial.newDataRequest(); var params = {}; params[opensocial.DataRequest.PeopleRequestFields.FIRST] = 9999; req.add(req.newFetchPeopleRequest('OWNER_FRIENDS', params), 'ownerFriends'); req.send(function(dataResponse) { Assert.assertDataResponseHadError(dataResponse, result, ['ownerFriends'], false); if (!dataResponse.hadError()) { var dataCollection = dataResponse.get('ownerFriends').getData(); Helper.addSubResult(result, 'Collection - getOffset > 0', Assert.assertTrue, dataCollection.getOffset() > 0, 'getOffset > 0'); } callback(result); }); } } ] }; MiscSuite.getFirstFriendId = function(){ var req = opensocial.newDataRequest(); req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.OWNER_FRIENDS), 'ownerFriends'); req.send(function(dataResponse) { if (!dataResponse.hadError()) { var ownerFriends = dataResponse.get('ownerFriends').getData().asArray(); return ownerFriends[0].getField(opensocial.Person.Field.ID); } else { return null; } }); }