1+ describe ( 'api tests' , ( ) => {
2+ before ( ( ) => {
3+ // Seed data
4+ cy . request ( '/x/test/seed' )
5+ } )
6+
7+ // Branches
8+ // Equivalent curl command:
9+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" -F dbowner="default" \
10+ // -F dbname="Assembly Election 2017.sqlite" https://localhost:9444/v1/branches
11+ it ( 'branches' , ( ) => {
12+ cy . request ( {
13+ method : 'POST' ,
14+ url : 'https://localhost:9444/v1/branches' ,
15+ form : true ,
16+ body : {
17+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
18+ dbowner : 'default' ,
19+ dbname : 'Assembly Election 2017.sqlite'
20+ } ,
21+ } ) . then (
22+ ( response ) => {
23+ expect ( response . status ) . to . eq ( 200 )
24+ let jsonBody = JSON . parse ( response . body )
25+ expect ( jsonBody ) . to . include . keys ( [ 'branches' , 'default_branch' ] )
26+ expect ( jsonBody ) . to . have . property ( 'default_branch' , 'main' )
27+ expect ( jsonBody . branches . main ) . to . have . property ( 'commit' )
28+ expect ( jsonBody . branches . main ) . to . have . property ( 'commit_count' , 1 )
29+ expect ( jsonBody . branches . main ) . to . have . property ( 'description' , '' )
30+ }
31+ )
32+ } )
33+
34+ // Columns
35+ // Equivalent curl command:
36+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
37+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
38+ // -F table="Candidate_Information" \
39+ // https://localhost:9444/v1/columns
40+ it ( 'columns' , ( ) => {
41+ cy . request ( {
42+ method : 'POST' ,
43+ url : 'https://localhost:9444/v1/columns' ,
44+ form : true ,
45+ body : {
46+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
47+ dbowner : 'default' ,
48+ dbname : 'Assembly Election 2017.sqlite' ,
49+ table : 'Candidate_Information'
50+ } ,
51+ } ) . then (
52+ ( response ) => {
53+ expect ( response . status ) . to . eq ( 200 )
54+ let jsonBody = JSON . parse ( response . body )
55+ expect ( jsonBody [ 0 ] ) . to . include . keys ( [ 'column_id' , 'default_value' , 'name' , 'not_null' ] )
56+ }
57+ )
58+ } )
59+
60+ // Commits
61+ // Equivalent curl command:
62+ // curl -k -F apikey="2MXwA5jGZkIQ3UNEcKsuDNSPMlx" \
63+ // -F dbowner="default" -F dbname="Assembly Election 2017.sqlite" \
64+ // https://localhost:9444/v1/commits
65+ it ( 'commits' , ( ) => {
66+ cy . request ( {
67+ method : 'POST' ,
68+ url : 'https://localhost:9444/v1/commits' ,
69+ form : true ,
70+ body : {
71+ apikey : '2MXwA5jGZkIQ3UNEcKsuDNSPMlx' ,
72+ dbowner : 'default' ,
73+ dbname : 'Assembly Election 2017.sqlite' ,
74+ } ,
75+ } ) . then (
76+ ( response ) => {
77+ expect ( response . status ) . to . eq ( 200 )
78+
79+ // Needs an extra step, due to the structure of the returned JSON
80+ let temp = JSON . parse ( response . body )
81+ let jsonBody = temp [ Object . keys ( temp ) [ 0 ] ]
82+
83+ expect ( jsonBody ) . to . have . property ( 'author_email' , 'default@dbhub.io' )
84+ expect ( jsonBody ) . to . have . property ( 'author_name' , 'Default system user' )
85+ expect ( jsonBody ) . to . have . property ( 'committer_email' , '' )
86+ expect ( jsonBody ) . to . have . property ( 'committer_name' , '' )
87+ expect ( jsonBody ) . to . have . property ( 'message' , 'Initial commit' )
88+ expect ( jsonBody ) . to . have . property ( 'other_parents' , null )
89+ expect ( jsonBody ) . to . have . property ( 'parent' , '' )
90+ expect ( jsonBody ) . to . include . keys ( [ 'id' , 'timestamp' , 'tree' ] )
91+
92+ // Test the "tree" entries
93+ let entries = jsonBody . tree . entries [ 0 ]
94+ expect ( entries ) . to . have . property ( 'entry_type' , 'db' )
95+ expect ( entries ) . to . have . property ( 'licence' , '9348ddfd44da5a127c59141981954746a860ec8e03e0412cf3af7134af0f97e2' )
96+ expect ( entries ) . to . have . property ( 'name' , 'Assembly Election 2017.sqlite' )
97+ expect ( entries ) . to . have . property ( 'sha256' , '4244d55013359c6476d06c045700139629ecfd2752ffad141984ba14ecafd17e' )
98+ expect ( entries ) . to . have . property ( 'size' , 57344 )
99+ expect ( entries ) . to . include . keys ( [ 'last_modified' ] )
100+ }
101+ )
102+ } )
103+ } )
0 commit comments