Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
035b7cc0
Commit
035b7cc0
authored
May 19, 2017
by
Winnie Hellmann
Committed by
Clement Ho
May 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add users endpoint to frontend API class
parent
776d4ba5
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
419 additions
and
114 deletions
+419
-114
app/assets/javascripts/api.js
app/assets/javascripts/api.js
+128
-101
app/assets/javascripts/blob/file_template_selector.js
app/assets/javascripts/blob/file_template_selector.js
+0
-3
app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
...s/javascripts/blob/template_selectors/ci_yaml_selector.js
+1
-1
app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
...avascripts/blob/template_selectors/dockerfile_selector.js
+1
-1
app/assets/javascripts/blob/template_selectors/gitignore_selector.js
...javascripts/blob/template_selectors/gitignore_selector.js
+1
-1
app/assets/javascripts/blob/template_selectors/license_selector.js
...s/javascripts/blob/template_selectors/license_selector.js
+1
-1
app/assets/javascripts/create_label.js
app/assets/javascripts/create_label.js
+1
-1
app/assets/javascripts/groups_select.js
app/assets/javascripts/groups_select.js
+1
-1
app/assets/javascripts/namespace_select.js
app/assets/javascripts/namespace_select.js
+1
-1
app/assets/javascripts/project_select.js
app/assets/javascripts/project_select.js
+1
-1
app/assets/javascripts/search.js
app/assets/javascripts/search.js
+1
-1
app/assets/javascripts/templates/issuable_template_selector.js
...ssets/javascripts/templates/issuable_template_selector.js
+1
-1
spec/javascripts/api_spec.js
spec/javascripts/api_spec.js
+281
-0
No files found.
app/assets/javascripts/api.js
View file @
035b7cc0
/* eslint-disable func-names, space-before-function-paren, quotes, object-shorthand, camelcase, no-var, comma-dangle, prefer-arrow-callback, quote-props, no-param-reassign, max-len */
var
Api
=
{
groupsPath
:
"
/api/:version/groups.json
"
,
groupPath
:
"
/api/:version/groups/:id.json
"
,
namespacesPath
:
"
/api/:version/namespaces.json
"
,
groupProjectsPath
:
"
/api/:version/groups/:id/projects.json
"
,
projectsPath
:
"
/api/:version/projects.json?simple=true
"
,
labelsPath
:
"
/:namespace_path/:project_path/labels
"
,
licensePath
:
"
/api/:version/templates/licenses/:key
"
,
gitignorePath
:
"
/api/:version/templates/gitignores/:key
"
,
gitlabCiYmlPath
:
"
/api/:version/templates/gitlab_ci_ymls/:key
"
,
dockerfilePath
:
"
/api/:version/templates/dockerfiles/:key
"
,
issuableTemplatePath
:
"
/:namespace_path/:project_path/templates/:type/:key
"
,
group
:
function
(
group_id
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
groupPath
)
.
replace
(
'
:id
'
,
group_id
);
import
$
from
'
jquery
'
;
const
Api
=
{
groupsPath
:
'
/api/:version/groups.json
'
,
groupPath
:
'
/api/:version/groups/:id.json
'
,
namespacesPath
:
'
/api/:version/namespaces.json
'
,
groupProjectsPath
:
'
/api/:version/groups/:id/projects.json
'
,
projectsPath
:
'
/api/:version/projects.json?simple=true
'
,
labelsPath
:
'
/:namespace_path/:project_path/labels
'
,
licensePath
:
'
/api/:version/templates/licenses/:key
'
,
gitignorePath
:
'
/api/:version/templates/gitignores/:key
'
,
gitlabCiYmlPath
:
'
/api/:version/templates/gitlab_ci_ymls/:key
'
,
dockerfilePath
:
'
/api/:version/templates/dockerfiles/:key
'
,
issuableTemplatePath
:
'
/:namespace_path/:project_path/templates/:type/:key
'
,
usersPath
:
'
/api/:version/users.json
'
,
group
(
groupId
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
groupPath
)
.
replace
(
'
:id
'
,
groupId
);
return
$
.
ajax
({
url
:
url
,
dataType
:
"
json
"
}).
done
(
function
(
group
)
{
return
callback
(
group
);
});
url
,
dataType
:
'
json
'
,
})
.
done
(
group
=>
callback
(
group
));
},
// Return groups list. Filtered by query
groups
:
function
(
query
,
options
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
groupsPath
);
groups
(
query
,
options
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
groupsPath
);
return
$
.
ajax
({
url
:
url
,
data
:
$
.
extend
({
url
,
data
:
Object
.
assign
({
search
:
query
,
per_page
:
20
per_page
:
20
,
},
options
),
dataType
:
"
json
"
}).
done
(
function
(
groups
)
{
return
callback
(
groups
);
});
dataType
:
'
json
'
,
})
.
done
(
groups
=>
callback
(
groups
));
},
// Return namespaces list. Filtered by query
namespaces
:
function
(
query
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
namespacesPath
);
namespaces
(
query
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
namespacesPath
);
return
$
.
ajax
({
url
:
url
,
url
,
data
:
{
search
:
query
,
per_page
:
20
per_page
:
20
,
},
dataType
:
"
json
"
}).
done
(
function
(
namespaces
)
{
return
callback
(
namespaces
);
});
dataType
:
'
json
'
,
}).
done
(
namespaces
=>
callback
(
namespaces
));
},
// Return projects list. Filtered by query
projects
:
function
(
query
,
options
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
projectsPath
);
projects
(
query
,
options
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
projectsPath
);
return
$
.
ajax
({
url
:
url
,
data
:
$
.
extend
({
url
,
data
:
Object
.
assign
({
search
:
query
,
per_page
:
20
,
membership
:
true
membership
:
true
,
},
options
),
dataType
:
"
json
"
}).
done
(
function
(
projects
)
{
return
callback
(
projects
);
});
dataType
:
'
json
'
,
})
.
done
(
projects
=>
callback
(
projects
));
},
newLabel
:
function
(
namespace_path
,
project_path
,
data
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
labelsPath
)
.
replace
(
'
:namespace_path
'
,
namespace_path
)
.
replace
(
'
:project_path
'
,
project_path
);
newLabel
(
namespacePath
,
projectPath
,
data
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
labelsPath
)
.
replace
(
'
:namespace_path
'
,
namespacePath
)
.
replace
(
'
:project_path
'
,
projectPath
);
return
$
.
ajax
({
url
:
url
,
type
:
"
POST
"
,
data
:
{
'
label
'
:
data
},
dataType
:
"
json
"
}).
done
(
function
(
label
)
{
return
callback
(
label
);
}).
error
(
function
(
message
)
{
return
callback
(
message
.
responseJSON
);
});
url
,
type
:
'
POST
'
,
data
:
{
label
:
data
},
dataType
:
'
json
'
,
})
.
done
(
label
=>
callback
(
label
))
.
error
(
message
=>
callback
(
message
.
responseJSON
));
},
// Return group projects list. Filtered by query
groupProjects
:
function
(
group_i
d
,
query
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
groupProjectsPath
)
.
replace
(
'
:id
'
,
group
_i
d
);
groupProjects
(
groupI
d
,
query
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
groupProjectsPath
)
.
replace
(
'
:id
'
,
group
I
d
);
return
$
.
ajax
({
url
:
url
,
url
,
data
:
{
search
:
query
,
per_page
:
20
per_page
:
20
,
},
dataType
:
"
json
"
}).
done
(
function
(
projects
)
{
return
callback
(
projects
);
});
dataType
:
'
json
'
,
})
.
done
(
projects
=>
callback
(
projects
));
},
// Return text for a specific license
licenseText
:
function
(
key
,
data
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
licensePath
)
licenseText
(
key
,
data
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
licensePath
)
.
replace
(
'
:key
'
,
key
);
return
$
.
ajax
({
url
:
url
,
data
:
data
}).
done
(
function
(
license
)
{
return
callback
(
license
);
});
url
,
data
,
})
.
done
(
license
=>
callback
(
license
));
},
gitignoreText
:
function
(
key
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
gitignorePath
)
gitignoreText
(
key
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
gitignorePath
)
.
replace
(
'
:key
'
,
key
);
return
$
.
get
(
url
,
function
(
gitignore
)
{
return
callback
(
gitignore
);
});
return
$
.
get
(
url
,
gitignore
=>
callback
(
gitignore
));
},
gitlabCiYml
:
function
(
key
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
gitlabCiYmlPath
)
gitlabCiYml
(
key
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
gitlabCiYmlPath
)
.
replace
(
'
:key
'
,
key
);
return
$
.
get
(
url
,
function
(
file
)
{
return
callback
(
file
);
});
return
$
.
get
(
url
,
file
=>
callback
(
file
));
},
dockerfileYml
:
function
(
key
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
dockerfilePath
).
replace
(
'
:key
'
,
key
);
dockerfileYml
(
key
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
dockerfilePath
).
replace
(
'
:key
'
,
key
);
$
.
get
(
url
,
callback
);
},
issueTemplate
:
function
(
namespacePath
,
projectPath
,
key
,
type
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
issuableTemplatePath
)
issueTemplate
(
namespacePath
,
projectPath
,
key
,
type
,
callback
)
{
const
url
=
Api
.
buildUrl
(
Api
.
issuableTemplatePath
)
.
replace
(
'
:key
'
,
key
)
.
replace
(
'
:type
'
,
type
)
.
replace
(
'
:project_path
'
,
projectPath
)
.
replace
(
'
:namespace_path
'
,
namespacePath
);
$
.
ajax
({
url
:
url
,
dataType
:
'
json
'
})
.
done
(
function
(
file
)
{
callback
(
null
,
file
);
})
.
error
(
callback
);
url
,
dataType
:
'
json
'
,
})
.
done
(
file
=>
callback
(
null
,
file
))
.
error
(
callback
);
},
buildUrl
:
function
(
url
)
{
users
(
query
,
options
)
{
const
url
=
Api
.
buildUrl
(
this
.
usersPath
);
return
Api
.
wrapAjaxCall
({
url
,
data
:
Object
.
assign
({
search
:
query
,
per_page
:
20
,
},
options
),
dataType
:
'
json
'
,
});
},
buildUrl
(
url
)
{
let
urlRoot
=
''
;
if
(
gon
.
relative_url_root
!=
null
)
{
url
=
gon
.
relative_url_root
+
url
;
url
Root
=
gon
.
relative_url_root
;
}
return
url
.
replace
(
'
:version
'
,
gon
.
api_version
);
}
return
urlRoot
+
url
.
replace
(
'
:version
'
,
gon
.
api_version
);
},
wrapAjaxCall
(
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// jQuery 2 is not Promises/A+ compatible (missing catch)
$
.
ajax
(
options
)
// eslint-disable-line promise/catch-or-return
.
then
(
data
=>
resolve
(
data
),
(
jqXHR
,
textStatus
,
errorThrown
)
=>
{
const
error
=
new
Error
(
`
${
options
.
url
}
:
${
errorThrown
}
`
);
error
.
textStatus
=
textStatus
;
reject
(
error
);
},
);
});
},
};
window
.
Api
=
Api
;
export
default
Api
;
app/assets/javascripts/blob/file_template_selector.js
View file @
035b7cc0
/* global Api */
export
default
class
FileTemplateSelector
{
constructor
(
mediator
)
{
this
.
mediator
=
mediator
;
...
...
@@ -65,4 +63,3 @@ export default class FileTemplateSelector {
this
.
reportSelection
(
opts
);
}
}
app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
View file @
035b7cc0
/* global Api */
import
Api
from
'
../../api
'
;
import
FileTemplateSelector
from
'
../file_template_selector
'
;
...
...
app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
View file @
035b7cc0
/* global Api */
import Api from '../../api';
import FileTemplateSelector from '../file_template_selector';
...
...
app/assets/javascripts/blob/template_selectors/gitignore_selector.js
View file @
035b7cc0
/* global Api */
import
Api
from
'
../../api
'
;
import
FileTemplateSelector
from
'
../file_template_selector
'
;
...
...
app/assets/javascripts/blob/template_selectors/license_selector.js
View file @
035b7cc0
/* global Api */
import
Api
from
'
../../api
'
;
import
FileTemplateSelector
from
'
../file_template_selector
'
;
...
...
app/assets/javascripts/create_label.js
View file @
035b7cc0
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-param-reassign, wrap-iife, max-len */
/* global Api */
import
Api
from
'
./api
'
;
class
CreateLabelDropdown
{
constructor
(
$el
,
namespacePath
,
projectPath
)
{
...
...
app/assets/javascripts/groups_select.js
View file @
035b7cc0
...
...
@@ -3,7 +3,7 @@
prefer-arrow-callback, comma-dangle, consistent-return, yoda,
prefer-rest-params, prefer-spread, no-unused-vars, prefer-template,
promise/catch-or-return */
/* global Api */
import
Api
from
'
./api
'
;
var
slice
=
[].
slice
;
...
...
app/assets/javascripts/namespace_select.js
View file @
035b7cc0
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, one-var, vars-on-top, one-var-declaration-per-line, comma-dangle, object-shorthand, no-else-return, prefer-template, quotes, prefer-arrow-callback, no-param-reassign, no-cond-assign, max-len */
/* global Api */
import
Api
from
'
./api
'
;
(
function
()
{
window
.
NamespaceSelect
=
(
function
()
{
...
...
app/assets/javascripts/project_select.js
View file @
035b7cc0
/* eslint-disable func-names, space-before-function-paren, wrap-iife, prefer-arrow-callback, no-var, comma-dangle, object-shorthand, one-var, one-var-declaration-per-line, no-else-return, quotes, max-len */
/* global Api */
import
Api
from
'
./api
'
;
(
function
()
{
this
.
ProjectSelect
=
(
function
()
{
...
...
app/assets/javascripts/search.js
View file @
035b7cc0
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, object-shorthand, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-else-return, max-len */
/* global Flash */
/* global Api */
import
Api
from
'
./api
'
;
(
function
()
{
this
.
Search
=
(
function
()
{
...
...
app/assets/javascripts/templates/issuable_template_selector.js
View file @
035b7cc0
/* eslint-disable comma-dangle, max-len, no-useless-return, no-param-reassign, max-len */
/* global Api */
import
Api
from
'
../api
'
;
import
TemplateSelector
from
'
../blob/template_selector
'
;
...
...
spec/javascripts/api_spec.js
0 → 100644
View file @
035b7cc0
import
Api
from
'
~/api
'
;
describe
(
'
Api
'
,
()
=>
{
const
dummyApiVersion
=
'
v3000
'
;
const
dummyUrlRoot
=
'
http://host.invalid
'
;
const
dummyGon
=
{
api_version
:
dummyApiVersion
,
relative_url_root
:
dummyUrlRoot
,
};
const
dummyResponse
=
'
hello from outer space!
'
;
const
sendDummyResponse
=
()
=>
{
const
deferred
=
$
.
Deferred
();
deferred
.
resolve
(
dummyResponse
);
return
deferred
.
promise
();
};
let
originalGon
;
beforeEach
(()
=>
{
originalGon
=
window
.
gon
;
window
.
gon
=
dummyGon
;
});
afterEach
(()
=>
{
window
.
gon
=
originalGon
;
});
describe
(
'
buildUrl
'
,
()
=>
{
it
(
'
adds URL root and fills in API version
'
,
()
=>
{
const
input
=
'
/api/:version/foo/bar
'
;
const
expectedOutput
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/foo/bar`
;
const
builtUrl
=
Api
.
buildUrl
(
input
);
expect
(
builtUrl
).
toEqual
(
expectedOutput
);
});
});
describe
(
'
group
'
,
()
=>
{
it
(
'
fetches a group
'
,
(
done
)
=>
{
const
groupId
=
'
123456
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/groups/
${
groupId
}
.json`
;
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
return
sendDummyResponse
();
});
Api
.
group
(
groupId
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
groups
'
,
()
=>
{
it
(
'
fetches groups
'
,
(
done
)
=>
{
const
query
=
'
dummy query
'
;
const
options
=
{
unused
:
'
option
'
};
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/groups.json`
;
const
expectedData
=
Object
.
assign
({
search
:
query
,
per_page
:
20
,
},
options
);
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
groups
(
query
,
options
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
namespaces
'
,
()
=>
{
it
(
'
fetches namespaces
'
,
(
done
)
=>
{
const
query
=
'
dummy query
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/namespaces.json`
;
const
expectedData
=
{
search
:
query
,
per_page
:
20
,
};
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
namespaces
(
query
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
projects
'
,
()
=>
{
it
(
'
fetches projects
'
,
(
done
)
=>
{
const
query
=
'
dummy query
'
;
const
options
=
{
unused
:
'
option
'
};
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/projects.json?simple=true`
;
const
expectedData
=
Object
.
assign
({
search
:
query
,
per_page
:
20
,
membership
:
true
,
},
options
);
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
projects
(
query
,
options
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
newLabel
'
,
()
=>
{
it
(
'
creates a new label
'
,
(
done
)
=>
{
const
namespace
=
'
some namespace
'
;
const
project
=
'
some project
'
;
const
labelData
=
{
some
:
'
data
'
};
const
expectedUrl
=
`
${
dummyUrlRoot
}
/
${
namespace
}
/
${
project
}
/labels`
;
const
expectedData
=
{
label
:
labelData
,
};
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
type
).
toEqual
(
'
POST
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
newLabel
(
namespace
,
project
,
labelData
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
groupProjects
'
,
()
=>
{
it
(
'
fetches group projects
'
,
(
done
)
=>
{
const
groupId
=
'
123456
'
;
const
query
=
'
dummy query
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/groups/
${
groupId
}
/projects.json`
;
const
expectedData
=
{
search
:
query
,
per_page
:
20
,
};
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
groupProjects
(
groupId
,
query
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
licenseText
'
,
()
=>
{
it
(
'
fetches a license text
'
,
(
done
)
=>
{
const
licenseKey
=
"
driver's license
"
;
const
data
=
{
unused
:
'
option
'
};
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/templates/licenses/
${
licenseKey
}
`
;
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
data
).
toEqual
(
data
);
return
sendDummyResponse
();
});
Api
.
licenseText
(
licenseKey
,
data
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
gitignoreText
'
,
()
=>
{
it
(
'
fetches a gitignore text
'
,
(
done
)
=>
{
const
gitignoreKey
=
'
ignore git
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/templates/gitignores/
${
gitignoreKey
}
`
;
spyOn
(
jQuery
,
'
get
'
).
and
.
callFake
((
url
,
callback
)
=>
{
expect
(
url
).
toEqual
(
expectedUrl
);
callback
(
dummyResponse
);
});
Api
.
gitignoreText
(
gitignoreKey
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
gitlabCiYml
'
,
()
=>
{
it
(
'
fetches a .gitlab-ci.yml
'
,
(
done
)
=>
{
const
gitlabCiYmlKey
=
'
Y CI ML
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/templates/gitlab_ci_ymls/
${
gitlabCiYmlKey
}
`
;
spyOn
(
jQuery
,
'
get
'
).
and
.
callFake
((
url
,
callback
)
=>
{
expect
(
url
).
toEqual
(
expectedUrl
);
callback
(
dummyResponse
);
});
Api
.
gitlabCiYml
(
gitlabCiYmlKey
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
dockerfileYml
'
,
()
=>
{
it
(
'
fetches a Dockerfile
'
,
(
done
)
=>
{
const
dockerfileYmlKey
=
'
a giant whale
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/templates/dockerfiles/
${
dockerfileYmlKey
}
`
;
spyOn
(
jQuery
,
'
get
'
).
and
.
callFake
((
url
,
callback
)
=>
{
expect
(
url
).
toEqual
(
expectedUrl
);
callback
(
dummyResponse
);
});
Api
.
dockerfileYml
(
dockerfileYmlKey
,
(
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
issueTemplate
'
,
()
=>
{
it
(
'
fetches an issue template
'
,
(
done
)
=>
{
const
namespace
=
'
some namespace
'
;
const
project
=
'
some project
'
;
const
templateKey
=
'
template key
'
;
const
templateType
=
'
template type
'
;
const
expectedUrl
=
`
${
dummyUrlRoot
}
/
${
namespace
}
/
${
project
}
/templates/
${
templateType
}
/
${
templateKey
}
`
;
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
return
sendDummyResponse
();
});
Api
.
issueTemplate
(
namespace
,
project
,
templateKey
,
templateType
,
(
error
,
response
)
=>
{
expect
(
error
).
toBe
(
null
);
expect
(
response
).
toBe
(
dummyResponse
);
done
();
});
});
});
describe
(
'
users
'
,
()
=>
{
it
(
'
fetches users
'
,
(
done
)
=>
{
const
query
=
'
dummy query
'
;
const
options
=
{
unused
:
'
option
'
};
const
expectedUrl
=
`
${
dummyUrlRoot
}
/api/
${
dummyApiVersion
}
/users.json`
;
const
expectedData
=
Object
.
assign
({
search
:
query
,
per_page
:
20
,
},
options
);
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
request
)
=>
{
expect
(
request
.
url
).
toEqual
(
expectedUrl
);
expect
(
request
.
dataType
).
toEqual
(
'
json
'
);
expect
(
request
.
data
).
toEqual
(
expectedData
);
return
sendDummyResponse
();
});
Api
.
users
(
query
,
options
)
.
then
((
response
)
=>
{
expect
(
response
).
toBe
(
dummyResponse
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment