Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dspace7 Angular
Manage
Activity
Members
Labels
Plan
Issues
42
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vtechworks
Dspace7 Angular
Commits
bac69f8b
Commit
bac69f8b
authored
6 years ago
by
Kristof De Langhe
Browse files
Options
Downloads
Patches
Plain Diff
Improved test coverage for registry service
parent
2925598f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/core/registry/registry.service.spec.ts
+143
-62
143 additions, 62 deletions
src/app/core/registry/registry.service.spec.ts
with
143 additions
and
62 deletions
src/app/core/registry/registry.service.spec.ts
+
143
−
62
View file @
bac69f8b
...
...
@@ -12,6 +12,24 @@ import { RequestEntry } from '../data/request.reducer';
import
{
RemoteData
}
from
'
../data/remote-data
'
;
import
{
PaginatedList
}
from
'
../data/paginated-list
'
;
import
{
PageInfo
}
from
'
../shared/page-info.model
'
;
import
{
GetRequest
}
from
'
../data/request.models
'
;
import
{
URLCombiner
}
from
'
../url-combiner/url-combiner
'
;
import
{
getMockRequestService
}
from
'
../../shared/mocks/mock-request.service
'
;
import
{
getMockResponseCacheService
}
from
'
../../shared/mocks/mock-response-cache.service
'
;
import
{
RegistryBitstreamformatsSuccessResponse
,
RegistryMetadatafieldsSuccessResponse
,
RegistryMetadataschemasSuccessResponse
,
SearchSuccessResponse
}
from
'
../cache/response-cache.models
'
;
import
{
SearchQueryResponse
}
from
'
../../+search-page/search-service/search-query-response.model
'
;
import
{
Component
}
from
'
@angular/core
'
;
import
{
RegistryMetadataschemasResponse
}
from
'
./registry-metadataschemas-response.model
'
;
import
{
RegistryMetadatafieldsResponse
}
from
'
./registry-metadatafields-response.model
'
;
import
{
RegistryBitstreamformatsResponse
}
from
'
./registry-bitstreamformats-response.model
'
;
@
Component
({
template
:
''
})
class
DummyComponent
{
}
describe
(
'
RegistryService
'
,
()
=>
{
let
registryService
:
RegistryService
;
...
...
@@ -100,101 +118,164 @@ describe('RegistryService', () => {
];
const
pageInfo
=
new
PageInfo
();
pageInfo
.
elementsPerPage
=
1
0
;
pageInfo
.
elementsPerPage
=
2
0
;
pageInfo
.
currentPage
=
1
;
const
endpoint
=
'
path
'
;
const
endpointWithParams
=
`
${
endpoint
}
?size=
${
pageInfo
.
elementsPerPage
}
&page=
${
pageInfo
.
currentPage
-
1
}
`
;
const
halServiceStub
=
{
getEndpoint
:
()
=>
Observable
.
of
(
'
path
'
)
getEndpoint
:
(
link
:
string
)
=>
Observable
.
of
(
endpoint
)
};
const
rdbMetadataschemasStub
=
{
toRemoteDataObservable
:
()
=>
{
const
payload
=
new
PaginatedList
(
pageInfo
,
mockSchemasList
);
const
remoteData
=
new
RemoteData
(
false
,
false
,
true
,
undefined
,
payload
);
return
Observable
.
of
(
remoteData
);
}
};
const
rdbMetadatafieldsStub
=
{
toRemoteDataObservable
:
()
=>
{
const
payload
=
new
PaginatedList
(
pageInfo
,
mockFieldsList
);
const
remoteData
=
new
RemoteData
(
false
,
false
,
true
,
undefined
,
payload
);
return
Observable
.
of
(
remoteData
);
}
};
const
rdbBitstreamformatsStub
=
{
toRemoteDataObservable
:
()
=>
{
const
payload
=
new
PaginatedList
(
pageInfo
,
mockFormatsList
);
const
remoteData
=
new
RemoteData
(
false
,
false
,
true
,
undefined
,
payload
);
return
Observable
.
of
(
remoteData
);
const
rdbStub
=
{
toRemoteDataObservable
:
(
requestEntryObs
:
Observable
<
RequestEntry
>
,
responseCacheObs
:
Observable
<
ResponseCacheEntry
>
,
payloadObs
:
Observable
<
any
>
)
=>
{
return
Observable
.
combineLatest
(
requestEntryObs
,
responseCacheObs
,
payloadObs
,
(
req
,
res
,
pay
)
=>
{
return
{
req
,
res
,
pay
};
});
},
aggregate
:
(
input
:
Array
<
Observable
<
RemoteData
<
any
>>>
):
Observable
<
RemoteData
<
any
[]
>>
=>
{
return
Observable
.
of
(
new
RemoteData
(
false
,
false
,
true
,
null
,
[]));
}
};
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
CommonModule
],
declarations
:
[
DummyComponent
],
providers
:
[
{
provide
:
ResponseCacheService
,
useValue
:
getMockResponseCacheService
()
},
{
provide
:
RequestService
,
useValue
:
getMockRequestService
()
},
{
provide
:
RemoteDataBuildService
,
useValue
:
rdbStub
},
{
provide
:
HALEndpointService
,
useValue
:
halServiceStub
},
RegistryService
]
});
registryService
=
TestBed
.
get
(
RegistryService
);
spyOn
((
registryService
as
any
).
halService
,
'
getEndpoint
'
).
and
.
returnValue
(
Observable
.
of
(
endpoint
));
});
describe
(
'
when requesting metadataschemas
'
,
()
=>
{
const
queryResponse
=
Object
.
assign
(
new
RegistryMetadataschemasResponse
(),
{
metadataschemas
:
mockSchemasList
,
page
:
pageInfo
});
const
response
=
new
RegistryMetadataschemasSuccessResponse
(
queryResponse
,
'
200
'
,
pageInfo
);
const
responseEntry
=
Object
.
assign
(
new
ResponseCacheEntry
(),
{
response
:
response
});
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
CommonModule
],
providers
:
[
{
provide
:
ResponseCacheService
,
useValue
:
{}
},
{
provide
:
RequestService
,
useValue
:
{}
},
{
provide
:
RemoteDataBuildService
,
useValue
:
rdbMetadataschemasStub
},
{
provide
:
HALEndpointService
,
useValue
:
halServiceStub
},
RegistryService
]
(
registryService
as
any
).
responseCache
.
get
.
and
.
returnValue
(
Observable
.
of
(
responseEntry
));
/* tslint:disable:no-empty */
registryService
.
getMetadataSchemas
(
pagination
).
subscribe
((
value
)
=>
{
});
/* tslint:enable:no-empty */
});
registryService
=
TestBed
.
get
(
RegistryService
);
it
(
'
should call getEndpoint on the halService
'
,
()
=>
{
expect
((
registryService
as
any
).
halService
.
getEndpoint
).
toHaveBeenCalled
();
});
it
(
'
should recieve the correct data
'
,
()
=>
{
registryService
.
getMetadataSchemas
(
pagination
).
subscribe
((
value
)
=>
{
expect
(
value
.
payload
.
page
[
0
].
prefix
).
toEqual
(
'
dc
'
);
});
it
(
'
should send out the request on the request service
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
configure
).
toHaveBeenCalled
();
});
it
(
'
should call getByHref on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
getByHref
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
it
(
'
should call get on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
responseCache
.
get
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
});
describe
(
'
when requesting metadatafields
'
,
()
=>
{
describe
(
'
when requesting metadataschema by name
'
,
()
=>
{
const
queryResponse
=
Object
.
assign
(
new
RegistryMetadataschemasResponse
(),
{
metadataschemas
:
mockSchemasList
,
page
:
pageInfo
});
const
response
=
new
RegistryMetadataschemasSuccessResponse
(
queryResponse
,
'
200
'
,
pageInfo
);
const
responseEntry
=
Object
.
assign
(
new
ResponseCacheEntry
(),
{
response
:
response
});
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
CommonModule
],
providers
:
[
{
provide
:
ResponseCacheService
,
useValue
:
{}
},
{
provide
:
RequestService
,
useValue
:
{}
},
{
provide
:
RemoteDataBuildService
,
useValue
:
rdbMetadatafieldsStub
},
{
provide
:
HALEndpointService
,
useValue
:
halServiceStub
},
RegistryService
]
(
registryService
as
any
).
responseCache
.
get
.
and
.
returnValue
(
Observable
.
of
(
responseEntry
));
/* tslint:disable:no-empty */
registryService
.
getMetadataSchemaByName
(
mockSchemasList
[
0
].
prefix
).
subscribe
((
value
)
=>
{
});
/* tslint:enable:no-empty */
});
it
(
'
should call getEndpoint on the halService
'
,
()
=>
{
expect
((
registryService
as
any
).
halService
.
getEndpoint
).
toHaveBeenCalled
();
});
registryService
=
TestBed
.
get
(
RegistryService
);
it
(
'
should send out the request on the request service
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
configure
).
toHaveBeenCalled
();
});
it
(
'
should recieve the correct data
'
,
()
=>
{
it
(
'
should call getByHref on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
getByHref
.
calls
.
argsFor
(
0
)[
0
]).
toContain
(
endpoint
);
});
it
(
'
should call get on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
responseCache
.
get
.
calls
.
argsFor
(
0
)[
0
]).
toContain
(
endpoint
);
});
});
describe
(
'
when requesting metadatafields
'
,
()
=>
{
const
queryResponse
=
Object
.
assign
(
new
RegistryMetadatafieldsResponse
(),
{
metadatafields
:
mockFieldsList
,
page
:
pageInfo
});
const
response
=
new
RegistryMetadatafieldsSuccessResponse
(
queryResponse
,
'
200
'
,
pageInfo
);
const
responseEntry
=
Object
.
assign
(
new
ResponseCacheEntry
(),
{
response
:
response
});
beforeEach
(()
=>
{
(
registryService
as
any
).
responseCache
.
get
.
and
.
returnValue
(
Observable
.
of
(
responseEntry
));
/* tslint:disable:no-empty */
registryService
.
getMetadataFieldsBySchema
(
mockSchemasList
[
0
],
pagination
).
subscribe
((
value
)
=>
{
expect
(
value
.
payload
.
page
[
0
].
element
).
toEqual
(
'
contributor
'
);
});
/* tslint:enable:no-empty */
});
it
(
'
should call getEndpoint on the halService
'
,
()
=>
{
expect
((
registryService
as
any
).
halService
.
getEndpoint
).
toHaveBeenCalled
();
});
it
(
'
should send out the request on the request service
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
configure
).
toHaveBeenCalled
();
});
it
(
'
should call getByHref on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
getByHref
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
it
(
'
should call get on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
responseCache
.
get
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
});
describe
(
'
when requesting bitstreamformats
'
,
()
=>
{
const
queryResponse
=
Object
.
assign
(
new
RegistryBitstreamformatsResponse
(),
{
bitstreamformats
:
mockFieldsList
,
page
:
pageInfo
});
const
response
=
new
RegistryBitstreamformatsSuccessResponse
(
queryResponse
,
'
200
'
,
pageInfo
);
const
responseEntry
=
Object
.
assign
(
new
ResponseCacheEntry
(),
{
response
:
response
});
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
CommonModule
],
providers
:
[
{
provide
:
ResponseCacheService
,
useValue
:
{}
},
{
provide
:
RequestService
,
useValue
:
{}
},
{
provide
:
RemoteDataBuildService
,
useValue
:
rdbBitstreamformatsStub
},
{
provide
:
HALEndpointService
,
useValue
:
halServiceStub
},
RegistryService
]
(
registryService
as
any
).
responseCache
.
get
.
and
.
returnValue
(
Observable
.
of
(
responseEntry
));
/* tslint:disable:no-empty */
registryService
.
getBitstreamFormats
(
pagination
).
subscribe
((
value
)
=>
{
});
/* tslint:enable:no-empty */
});
registryService
=
TestBed
.
get
(
RegistryService
);
it
(
'
should call getEndpoint on the halService
'
,
()
=>
{
expect
((
registryService
as
any
).
halService
.
getEndpoint
).
toHaveBeenCalled
();
});
it
(
'
should recieve the correct data
'
,
()
=>
{
registryService
.
getBitstreamFormats
(
pagination
).
subscribe
((
value
)
=>
{
expect
(
value
.
payload
.
page
[
0
].
shortDescription
).
toEqual
(
'
Unknown
'
);
});
it
(
'
should send out the request on the request service
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
configure
).
toHaveBeenCalled
();
});
it
(
'
should call getByHref on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
requestService
.
getByHref
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
it
(
'
should call get on the request service with the correct request url
'
,
()
=>
{
expect
((
registryService
as
any
).
responseCache
.
get
).
toHaveBeenCalledWith
(
endpointWithParams
);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment