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
39b48cdf
Commit
39b48cdf
authored
May 03, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RelatedIssuesService
See
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1797
parent
810aa419
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
0 deletions
+169
-0
app/assets/javascripts/issuable/related_issues/services/related_issues_service.js
...ssuable/related_issues/services/related_issues_service.js
+36
-0
spec/javascripts/issuable/related_issues/services/related_issues_service_spec.js
...le/related_issues/services/related_issues_service_spec.js
+133
-0
No files found.
app/assets/javascripts/issuable/related_issues/services/related_issues_service.js
0 → 100644
View file @
39b48cdf
import
Vue
from
'
vue
'
;
import
vueResource
from
'
vue-resource
'
;
Vue
.
use
(
vueResource
);
class
RelatedIssuesService
{
constructor
(
endpoint
)
{
this
.
relatedIssuesResource
=
Vue
.
resource
(
endpoint
);
}
// eslint-disable-next-line class-methods-use-this
fetchIssueInfo
(
endpoint
)
{
return
Vue
.
http
.
get
(
endpoint
)
.
then
(
res
=>
res
.
json
());
}
fetchRelatedIssues
()
{
return
this
.
relatedIssuesResource
.
get
()
.
then
(
res
=>
res
.
json
());
}
addRelatedIssues
(
newIssueReferences
)
{
return
this
.
relatedIssuesResource
.
save
({},
{
issue_references
:
newIssueReferences
,
})
.
then
(
res
=>
res
.
json
());
}
// eslint-disable-next-line class-methods-use-this
removeRelatedIssue
(
endpoint
)
{
return
Vue
.
http
.
delete
(
endpoint
)
.
then
(
res
=>
res
.
json
());
}
}
export
default
RelatedIssuesService
;
spec/javascripts/issuable/related_issues/services/related_issues_service_spec.js
0 → 100644
View file @
39b48cdf
import
_
from
'
underscore
'
;
import
Vue
from
'
vue
'
;
import
RelatedIssuesService
from
'
~/issuable/related_issues/services/related_issues_service
'
;
const
issuable1
=
{
reference
:
'
foo/bar#123
'
,
title
:
'
some title
'
,
path
:
'
/foo/bar/issues/123
'
,
state
:
'
opened
'
,
destroy_relation_path
:
'
/foo/bar/issues/123/related_issues/1
'
,
};
describe
(
'
RelatedIssuesService
'
,
()
=>
{
let
service
;
beforeEach
(()
=>
{
service
=
new
RelatedIssuesService
(
''
);
});
describe
(
'
fetchIssueInfo
'
,
()
=>
{
const
interceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
(
issuable1
),
{
status
:
200
,
}));
};
beforeEach
(()
=>
{
Vue
.
http
.
interceptors
.
push
(
interceptor
);
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
});
it
(
'
fetch issue info
'
,
(
done
)
=>
{
service
.
fetchIssueInfo
(
'
...
'
)
.
then
((
issue
)
=>
{
expect
(
issue
).
toEqual
(
issuable1
);
done
();
})
.
catch
((
err
)
=>
{
done
.
fail
(
`Failed to fetch issue:\n
${
err
}
`
);
});
});
});
describe
(
'
fetchRelatedIssues
'
,
()
=>
{
const
interceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([
issuable1
]),
{
status
:
200
,
}));
};
beforeEach
(()
=>
{
Vue
.
http
.
interceptors
.
push
(
interceptor
);
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
});
it
(
'
fetch related issues
'
,
(
done
)
=>
{
service
.
fetchRelatedIssues
()
.
then
((
relatedIssues
)
=>
{
expect
(
relatedIssues
).
toEqual
([
issuable1
]);
done
();
})
.
catch
((
err
)
=>
{
done
.
fail
(
`Failed to fetch related issues:\n
${
err
}
`
);
});
});
});
describe
(
'
addRelatedIssues
'
,
()
=>
{
const
interceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
({
message
:
`
${
issuable1
.
reference
}
was successfully related`
,
status
:
'
success
'
,
}),
{
status
:
200
,
}));
};
beforeEach
(()
=>
{
Vue
.
http
.
interceptors
.
push
(
interceptor
);
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
});
it
(
'
add related issues
'
,
(
done
)
=>
{
service
.
addRelatedIssues
([
issuable1
.
reference
])
.
then
((
resData
)
=>
{
expect
(
resData
.
status
).
toEqual
(
'
success
'
);
done
();
})
.
catch
((
err
)
=>
{
done
.
fail
(
`Failed to add related issues:\n
${
err
}
`
);
});
});
});
describe
(
'
removeRelatedIssue
'
,
()
=>
{
const
interceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
({
message
:
'
Relation was removed
'
,
status
:
'
success
'
,
}),
{
status
:
200
,
}));
};
beforeEach
(()
=>
{
Vue
.
http
.
interceptors
.
push
(
interceptor
);
});
afterEach
(()
=>
{
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
interceptor
);
});
it
(
'
remove related issue
'
,
(
done
)
=>
{
service
.
removeRelatedIssue
(
'
...
'
)
.
then
((
resData
)
=>
{
expect
(
resData
.
status
).
toEqual
(
'
success
'
);
done
();
})
.
catch
((
err
)
=>
{
done
.
fail
(
`Failed to fetch issue:\n
${
err
}
`
);
});
});
});
});
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