2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
2021-09-04 01:27:46 +05:30
|
|
|
require_migration!('remove_invalid_jira_data')
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe RemoveInvalidJiraData do
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:jira_tracker_data) { table(:jira_tracker_data) }
|
|
|
|
let(:services) { table(:services) }
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:service) { services.create!(id: 1) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:data) do
|
|
|
|
{
|
|
|
|
service_id: service.id,
|
|
|
|
encrypted_api_url: 'http:url.com',
|
|
|
|
encrypted_api_url_iv: 'somevalue',
|
|
|
|
encrypted_url: 'http:url.com',
|
|
|
|
encrypted_url_iv: 'somevalue',
|
|
|
|
encrypted_username: 'username',
|
|
|
|
encrypted_username_iv: 'somevalue',
|
|
|
|
encrypted_password: 'username',
|
|
|
|
encrypted_password_iv: 'somevalue'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let!(:valid_data) { jira_tracker_data.create!(data) }
|
|
|
|
let!(:empty_data) { jira_tracker_data.create!(service_id: service.id) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:invalid_api_url) do
|
|
|
|
data[:encrypted_api_url_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:missing_api_url) do
|
|
|
|
data[:encrypted_api_url] = ''
|
|
|
|
data[:encrypted_api_url_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:invalid_url) do
|
|
|
|
data[:encrypted_url_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:missing_url) do
|
|
|
|
data[:encrypted_url] = ''
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:invalid_username) do
|
|
|
|
data[:encrypted_username_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:missing_username) do
|
|
|
|
data[:encrypted_username] = nil
|
|
|
|
data[:encrypted_username_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:invalid_password) do
|
|
|
|
data[:encrypted_password_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:missing_password) do
|
|
|
|
data[:encrypted_password] = nil
|
|
|
|
data[:encrypted_username_iv] = nil
|
2021-02-22 17:27:13 +05:30
|
|
|
jira_tracker_data.create!(data)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the invalid data' do
|
|
|
|
valid_data_records = [valid_data, empty_data, missing_api_url, missing_url, missing_username, missing_password]
|
|
|
|
|
|
|
|
expect { migrate! }.to change { jira_tracker_data.count }.from(10).to(6)
|
|
|
|
|
|
|
|
expect(jira_tracker_data.all).to match_array(valid_data_records)
|
|
|
|
end
|
|
|
|
end
|