github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/tests/system/lib/import.rb (about) 1 class Import 2 def doctype 3 "io.cozy.imports" 4 end 5 6 def initialize(inst, link) 7 @inst = inst 8 @link = link 9 end 10 11 def precheck 12 body = JSON.generate data: { attributes: { url: @link } } 13 opts = { 14 accept: "application/vnd.api+json", 15 authorization: "Bearer #{@inst.token_for doctype}" 16 } 17 @inst.client["/move/imports/precheck"].post body, opts 18 # It raises an exception if the status code is 4xx 19 end 20 21 def run 22 body = JSON.generate data: { attributes: { url: @link } } 23 opts = { 24 accept: "application/vnd.api+json", 25 authorization: "Bearer #{@inst.token_for doctype}" 26 } 27 @inst.client["/move/imports"].post body, opts 28 end 29 30 def wait_done(timeout = 120) 31 timeout.times do 32 sleep 1 33 received = Email.received kind: "to", query: @inst.email 34 return if received.any? 35 end 36 raise "Import mail was not received after #{timeout} seconds" 37 end 38 end