-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
148 additions
and
117 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
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 was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
HUB_DATABASE_URL=mysql://root:[email protected]:3306/hub_test | ||
SEQ_DATABASE_URL=mysql://root:[email protected]:3306/hub_test | ||
NODE_ENV=test |
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 |
---|---|---|
@@ -1,9 +1,60 @@ | ||
import fetch from 'node-fetch'; | ||
import db from '../../src/helpers/mysql'; | ||
import fixtures from '../fixtures/spaces'; | ||
|
||
const HOST = `http://localhost:${process.env.PORT || 3030}`; | ||
|
||
describe('GET /api/space/:key', () => { | ||
beforeAll(async () => { | ||
await db.queryAsync('DELETE from spaces'); | ||
await Promise.all( | ||
fixtures.map(f => { | ||
return db.queryAsync('INSERT INTO spaces SET ?', { | ||
...f, | ||
settings: JSON.stringify(f.settings) | ||
}); | ||
}) | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await db.queryAsync('DELETE from spaces'); | ||
await db.endAsync(); | ||
}); | ||
|
||
describe('when the space exists', () => { | ||
it.todo('returns a space object'); | ||
let response; | ||
beforeAll(async () => { | ||
response = await fetch(`${HOST}/api/spaces/fabien.eth`); | ||
}); | ||
|
||
it('returns the correct HTTP response', () => { | ||
expect(response.status); | ||
expect(response.headers.get('content-type')).toContain('application/json'); | ||
}); | ||
|
||
it('returns the space data', async () => { | ||
const space = fixtures[0]; | ||
const expectedSpace = { | ||
flagged: space.flagged, | ||
verified: space.verified, | ||
...space.settings | ||
}; | ||
|
||
expect(response.json()).resolves.toEqual(expectedSpace); | ||
}); | ||
}); | ||
|
||
describe('when the space does not exist', () => { | ||
it.todo('returns a 404 error'); | ||
it('returns a 404 error', async () => { | ||
const response = await fetch(`${HOST}/api/spaces/null.eth`); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.headers.get('content-type')).toContain('application/json'); | ||
expect(response.json()).resolves.toEqual({ | ||
error: 'unauthorized', | ||
error_description: 'not_found' | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const fixtures: Record<string, any>[] = [ | ||
{ | ||
id: 'fabien.eth', | ||
name: 'Fabien.eth', | ||
flagged: false, | ||
verified: true, | ||
settings: { network: 1 }, | ||
created_at: Math.floor(Date.now() / 1e3), | ||
updated_at: Math.floor(Date.now() / 1e3) | ||
} | ||
]; | ||
|
||
export default fixtures; |
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
Oops, something went wrong.