Update spec after new import file validation

This commit is contained in:
Maikel Linke
2023-05-17 15:18:29 +10:00
parent fcb8550cb1
commit eaf3bd0bae

View File

@@ -12,15 +12,17 @@ describe "Product Import", type: :request do
expect(response).to redirect_to %r|#/login$|
end
it "rejects non-csv files" do
it "raises an error on non-csv files" do
login_as_admin
post admin_product_import_process_async_path, params: {
filepath: "/etc/passwd",
}, as: :json
expect do
post admin_product_import_process_async_path, params: {
filepath: "/etc/passwd",
}, as: :json
end
.to raise_error "Invalid File Path"
expect(response).to have_http_status :ok
expect(response.body).to eq "undefined method `validate_all' for nil:NilClass"
# The user just sees a server error.
end
it "raises an error when csv file doesn't exist" do
@@ -31,29 +33,46 @@ describe "Product Import", type: :request do
filepath: "/file/does/not/exist.csv",
}, as: :json
end
# This would result in server error and we know the file doesn't exist.
.to raise_error(
Errno::ENOENT,
"No such file or directory @ rb_sysopen - /file/does/not/exist.csv"
)
.to raise_error "Invalid File Path"
# The user just sees a server error.
end
it "tries to read any csv file" do
it "raises an error non unauthorized csv file" do
login_as_admin
# This could point to a secret file in the file system:
existing_file = Rails.public_path.join('inventory_template.csv').to_s
post admin_product_import_process_async_path, params: {
filepath: existing_file,
start: 1,
end: 5,
}, as: :json
expect do
post admin_product_import_process_async_path, params: {
filepath: existing_file,
start: 1,
end: 5,
}, as: :json
end
.to raise_error "Invalid File Path"
# No error, the file exists:
expect(response).to have_http_status :ok
# But it doesn't contain product data:
expect(response.body).to eq '{"entries":"{}","reset_counts":{}}'
# The user just sees a server error.
end
it "raises an error on valid but missing csv file" do
login_as_admin
# This could point to a secret file in the file system:
directory = Dir.mktmpdir("product_import")
missing_valid_file = File.join(directory, "import.csv").to_s
expect do
post admin_product_import_process_async_path, params: {
filepath: missing_valid_file,
start: 1,
end: 5,
}, as: :json
end
.to raise_error "Invalid File Path"
# The user just sees a server error.
end
end
end