Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/app/core/record-works/record-works.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,43 @@ describe('RecordWorksService', () => {
expect(service).toBeTruthy()
})

// Changing visibility is a state change. Over GET it needs no CSRF token, so a link or an
// image tag on any page could trigger it for a signed-in reader.
describe('visibility changes', () => {
// the service reloads the works list once the change lands; drain those so verify() passes
function drainPendingRequests(): void {
for (let i = 0; i < 5; i++) {
const pending = httpTestingController.match(() => true)
if (pending.length === 0) {
return
}
pending.forEach((r) => r.flush({}))
}
}

it('sends updateVisibility as a POST', () => {
service.updateVisibility('123', 'PRIVATE').subscribe()

const req = httpTestingController.expectOne(
runtimeEnvironment.API_WEB + 'works/123/visibility/PRIVATE'
)
expect(req.request.method).toEqual('POST')
req.flush({})
drainPendingRequests()
})

it('sends the bulk visibility change as a POST', () => {
service.visibility(['123', '456'], 'PUBLIC').subscribe()

const req = httpTestingController.expectOne(
runtimeEnvironment.API_WEB + 'works/123,456/visibility/PUBLIC'
)
expect(req.request.method).toEqual('POST')
req.flush({})
drainPendingRequests()
})
})

it('should call the method `save` 5 times and only `getWorks` and `getWorksGroupingSuggestions` once', () => {
const works: Work[] = getNumberOfWorks(5)

Expand Down
10 changes: 6 additions & 4 deletions src/app/core/record-works/record-works.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,13 @@ export class RecordWorksService {
}

return this._http
.get(
.post(
runtimeEnvironment.API_WEB +
'works/' +
putCode +
'/visibility/' +
visibility
visibility,
null
)
.pipe(
retryTransient(),
Expand Down Expand Up @@ -525,12 +526,13 @@ export class RecordWorksService {
visibility: VisibilityStrings
): Observable<any> {
return this._http
.get(
.post(
runtimeEnvironment.API_WEB +
'works/' +
putCodes.join(',') +
'/visibility/' +
visibility
visibility,
null
)
.pipe(
retryTransient(),
Expand Down
Loading