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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b394ef8d
Commit
b394ef8d
authored
Jan 04, 2021
by
Justin Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Jira connect api calls to use axios
parent
5f003f9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
25 deletions
+112
-25
app/assets/javascripts/jira_connect/api.js
app/assets/javascripts/jira_connect/api.js
+24
-0
app/assets/javascripts/jira_connect/index.js
app/assets/javascripts/jira_connect/index.js
+13
-25
spec/frontend/jira_connect/api_spec.js
spec/frontend/jira_connect/api_spec.js
+75
-0
No files found.
app/assets/javascripts/jira_connect/api.js
0 → 100644
View file @
b394ef8d
import
axios
from
'
axios
'
;
const
getJwt
=
async
()
=>
{
return
AP
.
context
.
getToken
();
};
export
const
addSubscription
=
async
(
addPath
,
namespace
)
=>
{
const
jwt
=
await
getJwt
();
return
axios
.
post
(
addPath
,
{
jwt
,
namespace_path
:
namespace
,
});
};
export
const
removeSubscription
=
async
(
removePath
)
=>
{
const
jwt
=
await
getJwt
();
return
axios
.
delete
(
removePath
,
{
params
:
{
jwt
,
},
});
};
app/assets/javascripts/jira_connect/index.js
View file @
b394ef8d
import
Vue
from
'
vue
'
;
import
$
from
'
jquery
'
;
import
App
from
'
./components/app.vue
'
;
import
{
addSubscription
,
removeSubscription
}
from
'
~/jira_connect/api
'
;
const
store
=
{
state
:
{
...
...
@@ -35,38 +36,25 @@ const initJiraFormHandlers = () => {
});
$
(
'
#add-subscription-form
'
).
on
(
'
submit
'
,
function
onAddSubscriptionForm
(
e
)
{
const
actionUrl
=
$
(
this
).
attr
(
'
action
'
);
const
addPath
=
$
(
this
).
attr
(
'
action
'
);
const
namespace
=
$
(
'
#namespace-input
'
).
val
();
e
.
preventDefault
();
AP
.
context
.
getToken
((
token
)
=>
{
// eslint-disable-next-line no-jquery/no-ajax
$
.
post
(
actionUrl
,
{
jwt
:
token
,
namespace_path
:
$
(
'
#namespace-input
'
).
val
(),
format
:
'
json
'
,
})
.
done
(
reqComplete
)
.
fail
((
err
)
=>
reqFailed
(
err
,
'
Failed to add namespace. Please try again.
'
));
});
addSubscription
(
addPath
,
namespace
)
.
then
(
reqComplete
)
.
catch
((
err
)
=>
reqFailed
(
err
.
response
.
data
,
'
Failed to add namespace. Please try again.
'
));
});
$
(
'
.remove-subscription
'
).
on
(
'
click
'
,
function
onRemoveSubscriptionClick
(
e
)
{
const
href
=
$
(
this
).
attr
(
'
href
'
);
const
removePath
=
$
(
this
).
attr
(
'
href
'
);
e
.
preventDefault
();
AP
.
context
.
getToken
((
token
)
=>
{
// eslint-disable-next-line no-jquery/no-ajax
$
.
ajax
({
url
:
href
,
method
:
'
DELETE
'
,
data
:
{
jwt
:
token
,
format
:
'
json
'
,
},
})
.
done
(
reqComplete
)
.
fail
((
err
)
=>
reqFailed
(
err
,
'
Failed to remove namespace. Please try again.
'
));
});
removeSubscription
(
removePath
)
.
then
(
reqComplete
)
.
catch
((
err
)
=>
reqFailed
(
err
.
response
.
data
,
'
Failed to remove namespace. Please try again.
'
),
);
});
};
...
...
spec/frontend/jira_connect/api_spec.js
0 → 100644
View file @
b394ef8d
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
httpStatus
from
'
~/lib/utils/http_status
'
;
import
{
addSubscription
,
removeSubscription
}
from
'
~/jira_connect/api
'
;
describe
(
'
JiraConnect API
'
,
()
=>
{
let
mock
;
let
response
;
const
addPath
=
'
addPath
'
;
const
removePath
=
'
removePath
'
;
const
namespace
=
'
namespace
'
;
const
jwt
=
'
jwt
'
;
const
successResponse
=
{
success
:
true
};
const
tokenSpy
=
jest
.
fn
().
mockReturnValue
(
jwt
);
window
.
AP
=
{
context
:
{
getToken
:
tokenSpy
,
},
};
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
mock
.
restore
();
response
=
null
;
});
describe
(
'
addSubscription
'
,
()
=>
{
const
makeRequest
=
()
=>
addSubscription
(
addPath
,
namespace
);
it
(
'
returns success response
'
,
async
()
=>
{
jest
.
spyOn
(
axios
,
'
post
'
);
mock
.
onPost
(
addPath
,
{
jwt
,
namespace_path
:
namespace
,
})
.
replyOnce
(
httpStatus
.
OK
,
successResponse
);
response
=
await
makeRequest
();
expect
(
tokenSpy
).
toHaveBeenCalled
();
expect
(
axios
.
post
).
toHaveBeenCalledWith
(
addPath
,
{
jwt
,
namespace_path
:
namespace
,
});
expect
(
response
.
data
).
toEqual
(
successResponse
);
});
});
describe
(
'
removeSubscription
'
,
()
=>
{
const
makeRequest
=
()
=>
removeSubscription
(
removePath
);
it
(
'
returns success response
'
,
async
()
=>
{
jest
.
spyOn
(
axios
,
'
delete
'
);
mock
.
onDelete
(
removePath
).
replyOnce
(
httpStatus
.
OK
,
successResponse
);
response
=
await
makeRequest
();
expect
(
tokenSpy
).
toHaveBeenCalled
();
expect
(
axios
.
delete
).
toHaveBeenCalledWith
(
removePath
,
{
params
:
{
jwt
,
},
});
expect
(
response
.
data
).
toEqual
(
successResponse
);
});
});
});
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