debian-mirror-gitlab/qa/spec/factory/resource/user_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2021-01-03 14:25:43 +05:30
RSpec.describe QA::Resource::User do
2018-12-13 13:39:08 +05:30
describe "#fabricate_via_api!" do
2020-05-24 23:13:21 +05:30
response = Struct.new(:code, :body)
2018-12-13 13:39:08 +05:30
it 'fetches an existing user' do
existing_users = [
{
id: '0',
name: 'name',
username: 'name',
web_url: ''
}
]
2020-05-24 23:13:21 +05:30
users_response = response.new('200', JSON.dump(existing_users))
single_user_response = response.new('200', JSON.dump(existing_users.first))
2018-12-13 13:39:08 +05:30
expect(subject).to receive(:api_get_from).with("/users?username=name").and_return(users_response)
expect(subject).to receive(:api_get_from).with("/users/0").and_return(single_user_response)
subject.username = 'name'
subject.fabricate_via_api!
expect(subject.api_response).to eq(existing_users.first)
end
it 'tries to create a user if it does not exist' do
2020-05-24 23:13:21 +05:30
expect(subject).to receive(:api_get_from).with("/users?username=foo").and_return(response.new('200', '[]'))
2018-12-13 13:39:08 +05:30
expect(subject).to receive(:api_post).and_return({ web_url: '' })
subject.username = 'foo'
subject.fabricate_via_api!
end
end
end