summaryrefslogtreecommitdiffstats
path: root/tests/integration/feeds.bats
blob: 5ad52dc30b3f56c645f974f047c7b19d039c7532 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bats

load "helpers/settings"

TESTSUITE="Feeds"

teardown() {
  ID=$(./occ news:feed:list 'admin' | grep "Something-${BATS_SUITE_TEST_NUMBER}" -2  | head -1 | grep -oE '[0-9]*')
  if [ -n "$ID" ]; then
    ./occ news:feed:delete "$user" "$ID"
  fi
}

@test "[$TESTSUITE] Create new" {
  run "./occ" news:feed:add "$user" "$NC_FEED"
  [ "$status" -eq 0 ]

  if ! echo "$output" | grep '"ID":'; then
    ret_status=$?
    echo "Feed ID not returned"
    return $ret_status
  fi
}

@test "[$TESTSUITE] Add feed without GUIDs" {
  run ./occ news:feed:add "$user" "$NO_GUID_FEED"
  [ "$status" -ne 0 ]

  if ! echo "$output" | grep "No parser can handle this stream"; then
    ret_status=$?
    echo "Malformed feed exception wasn't properly caught"
    return $ret_status
  fi
}

@test "[$TESTSUITE] List all" {
  ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}"

  run ./occ news:feed:list "$user"
  [ "$status" -eq 0 ]

  if ! echo "$output" | grep "Something-${BATS_SUITE_TEST_NUMBER}"; then
    ret_status=$?
    echo "Feed not found in list"
    return $ret_status
  fi

}

@test "[$TESTSUITE] Favicon" {
  ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}"
  ./occ news:feed:add "$user" "$HEISE_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}"

  run ./occ news:feed:list "$user"
  [ "$status" -eq 0 ]
    
  if ! echo "$output" | grep -F '"faviconLink": "https:\/\/nextcloud.com\/media\/screenshot-150x150.png"'; then
    ret_status=$?
    echo "Logo test failed"
    return $ret_status
  fi

  if ! echo "$output" | grep -F '"faviconLink": "https:\/\/www.heise.de\/favicon.ico"'; then
    ret_status=$?
    echo "Favicon test failed"
    return $ret_status
  fi
}

@test "[$TESTSUITE] List all items" {
  ./occ news:feed:add "$user" "https://github.com/nextcloud/news/releases.atom" --title "Something-${BATS_SUITE_TEST_NUMBER}"

  TAG=$(curl --silent "https://api.github.com/repos/nextcloud/news/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
  ID=$(./occ news:feed:list 'admin' | grep 'github\.com' -1  | head -1 | grep -oE '[0-9]*')

  run ./occ news:item:list-feed "$user" "$ID" --limit 200
  [ "$status" -eq 0 ]

  if ! echo "$output" | grep "$TAG"; then
    ret_status=$?
    echo "Release not found in list"
    return $ret_status
  fi
}

@test "[$TESTSUITE] Read all" {
  ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}"

  run ./occ news:feed:list "$user"
  [ "$status" -eq 0 ]

  echo "$output" | grep "Something-${BATS_SUITE_TEST_NUMBER}"

  ID=$(./occ news:feed:list 'admin' | grep "Something-${BATS_SUITE_TEST_NUMBER}" -2  | head -1 | grep -oE '[0-9]*')
  run ./occ news:feed:read "$user" "$ID" -v
  [ "$status" -eq 0 ]

  if ! echo "$output" | grep "items as read"; then
    ret_status=$?
    echo "Feed not read"
    return $ret_status
  fi
}

@test "[$TESTSUITE] Delete all" {
  ./occ news:feed:add "$user" "$NC_FEED" --title "Something-${BATS_SUITE_TEST_NUMBER}"

  run ./occ news:feed:list "$user"
  [ "$status" -eq 0 ]

  echo "$output" | grep "Something-${BATS_SUITE_TEST_NUMBER}"

  ID=$(./occ news:feed:list 'admin' | grep "Something-${BATS_SUITE_TEST_NUMBER}" -2  | head -1 | grep -oE '[0-9]*')
  run ./occ news:feed:delete "$user" "$ID"
  [ "$status" -eq 0 ]
}