diaspora-ganggo.tx-rx.bats 3 KB
Newer Older
zauberstuhl's avatar
zauberstuhl committed
1
# vim:ft=sh
2 3

load test_helper
4
load ganggo_helper
5 6

@test "$btf create database" {
7
  create_database "g1"
8 9 10 11
  [ "$?" -eq 0 ]
}

@test "$btf start ganggo#1 server" {
12
  ganggo_start_server g1 "9000"
13 14 15
}

@test "$btf start diaspora#1 server" {
16
  start_app "d1" "3000" "testing_diaspora"$(latest_tag "diaspora")
17
  [ "$?" -eq 0 ]
18
  code=$(wait_for "docker logs $(container_id "d1")" "Starting Diaspora in production")
19 20 21 22 23 24 25
  echo "expected 0, got $code"
  [ "$code" -eq "0" ]
  # unicorn timeout
  sleep 15
}

@test "$btf create ganggo user" {
26
  ganggo_create_user g1 "http://$(container_ip "g1"):9000"
27 28 29
}

@test "$btf create diaspora user" {
30 31 32
  rails_runner d1 "User.build(
    username: 'd1', email: 'd1@d1.de', password: 'pppppp').save!"
  [ "$?" -eq 0 ]
33 34 35
}

@test "$btf setup user relations" {
36 37 38 39 40
  rails_runner "d1" "user = User.find_by(username: 'd1')
    person = Person.find_or_fetch_by_identifier('g1@$(container_ip "g1"):9000')
    aspect = Aspect.new(name: 'test', user_id: user.id)
    aspect.save!
    user.share_with(person, aspect)"
41 42 43 44 45 46 47 48
  [ "$?" -eq 0 ]
}

function send_type() {
  type=$1

  # should we send it publicly or limited
  if [ "$type" == "private" ]; then
49
    postType="public: false, aspect_ids: user.aspect_ids"
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  else
    postType="public: true"
  fi
  # send post via diaspora
  postID=$(rails_runner "d1" "user = User.find_by(username: 'd1');
            puts StatusMessageCreationService.new(user).create(
              status_message: {text: 'hello world'}, $postType
            ).id;")
  echo "postID = $postID"
  [ "$?" -eq 0 ]
  [ "$postID" -gt 0 ]

  # check if ganggo received it
  function cmd() {
    query "g1" "select count(*) from posts where public = true;"
  }
66
  code=$(wait_for cmd "1" 120)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  echo "expected 0, got $code"
  [ "$code" -eq "0" ]

  # send comment
  guid=$(rails_runner "d1" "user = User.find_by(username: 'd1');
          puts CommentService.new(user)
            .create($postID, 'commenttext').guid;")
  echo "guid = $guid"
  [ "$?" -eq 0 ]
  # XXX how to check guid
  #[ "$guid" != "null" ]

  # check comment
  function cmd() {
    query "g1" "select count(*) from comments where guid = '$guid';"
  }
83
  code=$(wait_for cmd "1" 120)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  echo "expected 0, got $code"
  [ "$code" -eq "0" ]

  # send like
  guid=$(rails_runner "d1" "user = User.find_by(username: 'd1');
          puts LikeService.new(user).create($postID).guid;")
  echo "guid = $guid"
  [ "$?" -eq 0 ]
  # XXX how to check guid
  #[ "$guid" != "null" ]

  # check comment
  function cmd() {
    query "g1" "select count(*) from likes where guid = '$guid';"
  }
99
  code=$(wait_for cmd "1" 120)
100 101 102 103 104 105 106 107 108 109 110 111 112
  echo "expected 0, got $code"
  [ "$code" -eq "0" ]
}

@test "$btf create public entities and check federation" {
  send_type public
}

@test "$btf create private entities and check federation" {
  send_type private
}

@test "$btf stop and delete containers" {
113 114 115 116 117 118
  for app in g1 d1; do
    stop_app $app
    [ "$?" -eq 0 ]
    remove_app $app
    [ "$?" -eq 0 ]
  done
119 120 121
}

@test "$btf drop databases" {
122
  drop_database "g1"
123
  [ "$?" -eq 0 ]
124
  drop_database "d1"
125 126
  [ "$?" -eq 0 ]
}