<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you 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.
-->
<Module>
  <ModulePrefs title="EndToEndTest">
    <Require feature="osapi" />
  </ModulePrefs>
  <Content type="html">
    <![CDATA[
      <script type="text/javascript" src="/testframework.js"></script>
      <script type="text/javascript">
        var tests = {
          /** Test fetching a specific ID's activities */
          fetchId: function() {
            function receivedData(response) {
              assertFalse("Should not have error", response.error);
              assertEquals("Should have 3 activities", 3, response.totalResults);
              finished();
            }
            osapi.activities.get({ userId : 'canonical', groupId : '@self'}).execute(receivedData);
          },
          /** Test fetching viewer's activity */
          fetchViewerActivities: function() {
            function receivedData(response) {
              assertFalse("Should not have error", response.error);
              assertEquals("Should have 1 activity", 1, response.totalResults);
              assertEquals("Titles don't match", "yellow", response.list[0].title);
              assertEquals("Body doesn't match", "what a color!", response.list[0].body);
              finished();
            }

            osapi.activities.get().execute(receivedData);
          },
          /** Test fetching viewer's friends' activities */
          fetchViewerFriendActivities: function() {
            function receivedData(response) {
              assertFalse("Should not have error", response.error);
              assertEquals("Should have 2 activities", 2, response.totalResults);
              assertEquals("Titles don't match", "Jane just posted a photo of a monkey", response.list[0].title);
              assertEquals("Body doesn't match", "and she thinks you look like him", response.list[0].body);
              assertEquals("Body doesn't match", "Jane says George likes yoda!", response.list[1].title);
              assertEquals("Body doesn't match", "or is it you?", response.list[1].body);
              finished();
            }

            osapi.activities.get({groupId : '@friends'}).execute(receivedData);
          },
          /** Test creating an activity */
          createNewActivity: function() {
            function newData(response) {
              assertFalse("Should not have error", response.error);
              assertEquals("Should have 3 activities", 3, response.totalResults);
              assertEquals("Titles don't match", "New activity", response.list[2].title);
              assertEquals("Body doesn't match", "Hey", response.list[2].body);
              finished();
            }

            function receivedData(response) {
              assertFalse("Should not have error", response.error);
              assertEquals("Should have 0 activities", undefined, response.totalResults);
              osapi.activities.get({userId:'canonical'}).execute(newData);
            }

            osapi.activities.create({userId:'canonical', activity : {title : 'New activity', body : 'Hey'}}).execute(receivedData);
          }


        };
      </script>
    ]]>
  </Content>
</Module>
