-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:decentraland/builder-server into …
…feat/add-virtual-third-parties
- Loading branch information
Showing
4 changed files
with
157 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ import { CurationStatus } from '../Curation' | |
import { ThirdPartyService } from '../ThirdParty/ThirdParty.service' | ||
import { ThirdParty } from '../ThirdParty/ThirdParty.types' | ||
import { isCommitteeMember } from '../Committee' | ||
import * as Warehouse from '../warehouse' | ||
import { app } from '../server' | ||
import { hasPublicAccess } from './access' | ||
import { toFullCollection } from './utils' | ||
|
@@ -79,6 +80,7 @@ import { | |
FullCollection, | ||
CollectionSort, | ||
CollectionTypeFilter, | ||
TermsOfServiceEvent, | ||
} from './Collection.types' | ||
|
||
const server = supertest(app.getApp()) | ||
|
@@ -94,6 +96,7 @@ jest.mock('../Committee') | |
jest.mock('../Item/Item.model') | ||
jest.mock('./Collection.model') | ||
jest.mock('./access') | ||
jest.mock('../warehouse') | ||
|
||
const ThirdPartyServiceMock = ThirdPartyService as jest.Mocked< | ||
typeof ThirdPartyService | ||
|
@@ -3140,4 +3143,94 @@ describe('Collection router', () => { | |
}) | ||
}) | ||
}) | ||
|
||
describe('when saving the ToS', () => { | ||
let body: any | ||
|
||
beforeEach(() => { | ||
url = `/collections/${dbCollectionMock.id}/tos` | ||
}) | ||
|
||
describe('and the collection does not exist', () => { | ||
beforeEach(() => { | ||
;(Collection.count as jest.Mock).mockResolvedValueOnce(0) | ||
body = { | ||
email: '[email protected]', | ||
} | ||
}) | ||
|
||
it('should throw a 404 error', () => { | ||
return server | ||
.post(buildURL(url)) | ||
.set(createAuthHeaders('post', url)) | ||
.send(body) | ||
.expect(404) | ||
.then((response: any) => { | ||
expect(response.body).toEqual({ | ||
data: { id: dbCollection.id, tableName: Collection.tableName }, | ||
error: `Couldn't find "${dbCollection.id}" on ${Collection.tableName}`, | ||
ok: false, | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('and the collection exists', () => { | ||
beforeEach(() => { | ||
;(Collection.count as jest.Mock).mockResolvedValueOnce(1) | ||
}) | ||
|
||
describe("and the ToS don't follow the schema", () => { | ||
beforeEach(() => { | ||
body = { | ||
email: 'This is not an email', | ||
} | ||
}) | ||
|
||
it('should throw a 400 error', () => { | ||
return server | ||
.post(buildURL(url)) | ||
.set(createAuthHeaders('post', url)) | ||
.send(body) | ||
.expect(400) | ||
.then((response: any) => { | ||
expect(response.body).toEqual({ | ||
data: expect.any(Object), | ||
error: 'Invalid request body', | ||
ok: false, | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('and the ToS is correct', () => { | ||
beforeEach(() => { | ||
;(Collection.findByIds as jest.Mock).mockResolvedValueOnce([ | ||
dbCollection, | ||
]) | ||
;(Warehouse.sendDataToWarehouse as jest.Mock).mockResolvedValueOnce( | ||
undefined | ||
) | ||
body = { | ||
email: '[email protected]', | ||
event: TermsOfServiceEvent.PUBLISH_THIRD_PARTY_ITEMS, | ||
hashes: ['hash1', 'hash2'], | ||
} | ||
}) | ||
|
||
it('should save the ToS and return a 200', () => { | ||
return server | ||
.post(buildURL(url)) | ||
.set(createAuthHeaders('post', url)) | ||
.send(body) | ||
.expect(200) | ||
.then((response: any) => { | ||
expect(response.body).toEqual({ | ||
ok: true, | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters