diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2018-11-02 12:39:07 -0400 |
---|---|---|
committer | Mark Lapierre <mlapierre@gitlab.com> | 2018-11-02 14:27:28 -0400 |
commit | 190afc62fb1e8753b2339d1d052b19a5da369c9e (patch) | |
tree | 928eb8d6a1fa3959049800ab8e942bf393afb14c /qa/spec | |
parent | 74b5dce44aa902364d7ff3a3d8f6a1fcd857993d (diff) | |
download | gitlab-ce-ml-create-user-via-api-qa.tar.gz |
Create users via the APIml-create-user-via-api-qa
Allows users to be fetched/created via the API.
Diffstat (limited to 'qa/spec')
-rw-r--r-- | qa/spec/factory/resource/user_spec.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/qa/spec/factory/resource/user_spec.rb b/qa/spec/factory/resource/user_spec.rb new file mode 100644 index 00000000000..2f6c59b3e69 --- /dev/null +++ b/qa/spec/factory/resource/user_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +describe QA::Factory::Resource::User do + describe "#fabricate_via_api!" do + Response = Struct.new(:code, :body) + + it 'fetches an existing user' do + existing_users = [ + { + id: '0', + name: 'name', + username: 'name', + web_url: '' + } + ] + users_response = Response.new('200', JSON.dump(existing_users)) + single_user_response = Response.new('200', JSON.dump(existing_users.first)) + + 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 + expect(subject).to receive(:api_get_from).with("/users?username=foo").and_return(Response.new('200', '[]')) + expect(subject).to receive(:api_post).and_return({ web_url: '' }) + + subject.username = 'foo' + subject.fabricate_via_api! + end + end +end |