-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdocument.bats
158 lines (125 loc) · 4.1 KB
/
document.bats
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env bats
load "helpers"
setup_file() {
start_server
login_superadmin
}
teardown_file() {
stop_server
}
@test "documents: can upload a file, retrieve, archive, delete, and verify deletion" {
# fake service account used in concourse
if echo "${SA_CREDS_BASE64}" | base64 -d | grep -q "abc_app"; then
skip
fi
# Create a customer
customer_email=$(generate_email)
telegramId=$(generate_email)
variables=$(
jq -n \
--arg email "$customer_email" \
--arg telegramId "$telegramId" \
'{
input: {
email: $email,
telegramId: $telegramId
}
}'
)
exec_admin_graphql 'customer-create' "$variables"
customer_id=$(graphql_output .data.customerCreate.customer.customerId)
[[ "$customer_id" != "null" ]] || exit 1
# Generate a temporary file
temp_file=$(mktemp)
echo "Test content" > "$temp_file"
# Prepare the variables for file upload
variables=$(jq -n \
--arg customerId "$customer_id" \
'{
"customerId": $customerId,
"file": null
}')
# Execute the GraphQL mutation for file upload
response=$(exec_admin_graphql_upload "customer-document-attach" "$variables" "$temp_file")
document_id=$(echo "$response" | jq -r '.data.customerDocumentAttach.document.documentId')
[[ "$document_id" != "" ]] || exit 1
# Clean up the temporary file
rm "$temp_file"
# Fetch the document by ID
variables=$(jq -n \
--arg documentId "$document_id" \
'{
"id": $documentId
}')
exec_admin_graphql 'document' "$variables"
fetched_document_id=$(graphql_output .data.document.documentId)
[[ "$fetched_document_id" == "$document_id" ]] || exit 1
fetched_customer_id=$(graphql_output .data.document.customerId)
[[ "$fetched_customer_id" == "$customer_id" ]] || exit 1
# Fetch documents for the customer
variables=$(jq -n \
--arg customerId "$customer_id" \
'{
"customerId": $customerId
}')
exec_admin_graphql 'documents-for-customer' "$variables"
documents_count=$(graphql_output '.data.customer.documents | length')
[[ "$documents_count" -ge 1 ]] || exit 1
first_document_id=$(graphql_output '.data.customer.documents[0].documentId')
[[ "$first_document_id" == "$document_id" ]] || exit 1
# Generate download link for the document
variables=$(jq -n \
--arg documentId "$document_id" \
'{
input: {
documentId: $documentId
}
}')
exec_admin_graphql 'document-download-link-generate' "$variables"
download_link=$(graphql_output .data.documentDownloadLinkGenerate.link)
[[ "$download_link" != "null" && "$download_link" != "" ]] || exit 1
response=$(curl -s -o /dev/null -w "%{http_code}" "$download_link")
[[ "$response" == "200" ]] || exit 1
# archive the document
variables=$(jq -n \
--arg documentId "$document_id" \
'{
input: {
documentId: $documentId
}
}')
exec_admin_graphql 'document-archive' "$variables"
status=$(graphql_output .data.documentArchive.document.status)
[[ "$status" == "ARCHIVED" ]] || exit 1
# Delete the document
variables=$(jq -n \
--arg documentId "$document_id" \
'{
input: {
documentId: $documentId
}
}')
exec_admin_graphql 'document-delete' "$variables"
deleted_document_id=$(graphql_output .data.documentDelete.deletedDocumentId)
[[ "$deleted_document_id" == "$document_id" ]] || exit 1
# Verify that the deleted document is no longer accessible
# Fetch documents for the customer again
variables=$(jq -n \
--arg customerId "$customer_id" \
'{
"customerId": $customerId
}')
exec_admin_graphql 'documents-for-customer' "$variables"
# Check if the deleted document is not in the list
documents=$(graphql_output '.data.customer.documents')
deleted_document_exists=$(echo "$documents" | jq --arg id "$document_id" 'any(.[]; .id == $id)')
[[ "$deleted_document_exists" == "false" ]] || exit 1
variables=$(jq -n \
--arg documentId "$document_id" \
'{
"id": $documentId
}')
exec_admin_graphql 'document' "$variables"
document=$(graphql_output '.document')
[[ "$document" == "null" ]] || exit 1
}