Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/qa/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-11-05 13:03:45 +0300
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-11-05 13:03:45 +0300
commit8ceb3dc3417baf8837b46cfc1d5207efe848d2c3 (patch)
treedc7d3670894fb179db2c6c984e70c1cd66a31aa1 /qa/spec
parente083e28eac832bd2b2bde0545f626f44af947298 (diff)
parent190afc62fb1e8753b2339d1d052b19a5da369c9e (diff)
Merge branch 'ml-create-user-via-api-qa' into 'master'
Create users via the API See merge request gitlab-org/gitlab-ce!22779
Diffstat (limited to 'qa/spec')
-rw-r--r--qa/spec/factory/resource/user_spec.rb36
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