]> git.notmuchmail.org Git - notmuch/blob - test/json
test: update tests to reflect the exclude flag
[notmuch] / test / json
1 #!/usr/bin/env bash
2 test_description="--format=json output"
3 . ./test-lib.sh
4
5 test_begin_subtest "Show message: json"
6 add_message "[subject]=\"json-show-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-show-message\""
7 output=$(notmuch show --format=json "json-show-message")
8 test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"json-show-message\n\"}]}, []]]]"
9
10 test_begin_subtest "Search message: json"
11 add_message "[subject]=\"json-search-subject\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"json-search-message\""
12 output=$(notmuch search --format=json "json-search-message" | notmuch_search_sanitize)
13 test_expect_equal "$output" "[{\"thread\": \"XXX\",
14 \"timestamp\": 946728000,
15 \"date_relative\": \"2000-01-01\",
16 \"matched\": 1,
17 \"total\": 1,
18 \"authors\": \"Notmuch Test Suite\",
19 \"subject\": \"json-search-subject\",
20 \"tags\": [\"inbox\", \"unread\"]}]"
21
22 test_begin_subtest "Show message: json, utf-8"
23 add_message "[subject]=\"json-show-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-show-méssage\""
24 output=$(notmuch show --format=json "jsön-show-méssage")
25 test_expect_equal "$output" "[[[{\"id\": \"${gen_msg_id}\", \"match\": true, \"excluded\": false, \"filename\": \"${gen_msg_filename}\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\",\"unread\"], \"headers\": {\"Subject\": \"json-show-utf8-body-sübjéct\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"text/plain\", \"content\": \"jsön-show-méssage\n\"}]}, []]]]"
26
27 test_begin_subtest "Show message: json, inline attachment filename"
28 subject='json-show-inline-attachment-filename'
29 id="json-show-inline-attachment-filename@notmuchmail.org"
30 emacs_deliver_message \
31     "$subject" \
32     'This is a test message with inline attachment with a filename' \
33     "(mml-attach-file \"$TEST_DIRECTORY/README\" nil nil \"inline\")
34      (message-goto-eoh)
35      (insert \"Message-ID: <$id>\n\")"
36 output=$(notmuch show --format=json "id:$id")
37 filename=$(notmuch search --output=files "id:$id")
38 test_expect_equal "$output" "[[[{\"id\": \"$id\", \"match\": true, \"excluded\": false, \"filename\": \"$filename\", \"timestamp\": 946728000, \"date_relative\": \"2000-01-01\", \"tags\": [\"inbox\"], \"headers\": {\"Subject\": \"$subject\", \"From\": \"Notmuch Test Suite <test_suite@notmuchmail.org>\", \"To\": \"test_suite@notmuchmail.org\", \"Date\": \"Sat, 01 Jan 2000 12:00:00 +0000\"}, \"body\": [{\"id\": 1, \"content-type\": \"multipart/mixed\", \"content\": [{\"id\": 2, \"content-type\": \"text/plain\", \"content\": \"This is a test message with inline attachment with a filename\"}, {\"id\": 3, \"content-type\": \"application/octet-stream\", \"filename\": \"README\"}]}]}, []]]]"
39
40 test_begin_subtest "Search message: json, utf-8"
41 add_message "[subject]=\"json-search-utf8-body-sübjéct\"" "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" "[body]=\"jsön-search-méssage\""
42 output=$(notmuch search --format=json "jsön-search-méssage" | notmuch_search_sanitize)
43 test_expect_equal "$output" "[{\"thread\": \"XXX\",
44 \"timestamp\": 946728000,
45 \"date_relative\": \"2000-01-01\",
46 \"matched\": 1,
47 \"total\": 1,
48 \"authors\": \"Notmuch Test Suite\",
49 \"subject\": \"json-search-utf8-body-sübjéct\",
50 \"tags\": [\"inbox\", \"unread\"]}]"
51
52 test_done