Открыть боковую панель
GitLab.org
Gitlab
Коммиты
770b3b1c
Коммит
770b3b1c
создал
Май 03, 2017
по автору
Eric Eastwood
Просмотр файлов
Add RelatedIssuesService
See
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1797
владелец
e315fe1d
Изменения
2
Скрыть пробелы
Построчно
Рядом
app/assets/javascripts/issuable/related_issues/services/related_issues_service.js
0 → 100644
Просмотр файла @
770b3b1c
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
Просмотр файла @
770b3b1c
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
}
`
);
});
});
});
});
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать