-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create propositions and view supports/supportedBy propositions (#…
…24) * fix: update target version and run yarn * feat: add the createProposition mutation * feat: add GREMLIN_PORT to apollo-start * refactor: supports and supportedBy should return propositions
- Loading branch information
1 parent
21ad6d0
commit 85b8825
Showing
17 changed files
with
198 additions
and
60 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 |
---|---|---|
@@ -1 +1 @@ | ||
10.13 | ||
lts/dubnium |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { getProposition } from '../../lib/proposition'; | ||
import Proposition from './Proposition'; | ||
|
||
jest.mock('../../lib/proposition', () => ({ | ||
getProposition: jest.fn(), | ||
})); | ||
|
||
(getProposition as jest.Mock<any>).mockImplementation(async id => ({ | ||
id, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'I am a proposition', | ||
})); | ||
|
||
const { supportedBy, supports } = Proposition; | ||
|
||
describe('Proposition', () => { | ||
describe('supportedBy', () => { | ||
it('returns a proposition for every id in the supportedBy property', async () => { | ||
expect.assertions(2); | ||
const [prop1, prop2] = supportedBy({ | ||
id: 0, | ||
supportedBy: [1, 2], | ||
supports: [], | ||
text: 'Supported proposition', | ||
}); | ||
await expect(prop1).resolves.toEqual({ | ||
id: 1, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'I am a proposition', | ||
}); | ||
await expect(prop2).resolves.toEqual({ | ||
id: 2, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'I am a proposition', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('supports', () => { | ||
it('returns a proposition for every id in the supports property', async () => { | ||
expect.assertions(2); | ||
const [prop1, prop2] = supports({ | ||
id: 0, | ||
supportedBy: [], | ||
supports: [1, 2], | ||
text: 'Supported proposition', | ||
}); | ||
await expect(prop1).resolves.toEqual({ | ||
id: 1, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'I am a proposition', | ||
}); | ||
await expect(prop2).resolves.toEqual({ | ||
id: 2, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'I am a proposition', | ||
}); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { map } from 'ramda'; | ||
import { getProposition, IProposition } from '../../lib/proposition'; | ||
|
||
function supports(proposition: IProposition) { | ||
return map(getProposition, proposition.supports); | ||
} | ||
|
||
function supportedBy(proposition: IProposition) { | ||
return map(getProposition, proposition.supportedBy); | ||
} | ||
|
||
export default { | ||
supportedBy, | ||
supports, | ||
}; |
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,35 @@ | ||
import { | ||
createProposition as _createProposition, | ||
INewProposition, | ||
IProposition, | ||
} from '../../lib/proposition'; | ||
import createProposition from './createProposition'; | ||
jest.mock('../../lib/proposition', () => ({ | ||
createProposition: jest.fn(), | ||
})); | ||
|
||
(_createProposition as jest.Mock<any>).mockImplementation( | ||
async (newProp: INewProposition): Promise<IProposition> => ({ | ||
...newProp, | ||
id: 0, | ||
}) | ||
); | ||
|
||
describe('createProposition', () => { | ||
it('creates a proposition', async () => { | ||
expect.assertions(2); | ||
await expect( | ||
createProposition({}, { text: 'All men are mortal' }) | ||
).resolves.toEqual({ | ||
id: 0, | ||
supportedBy: [], | ||
supports: [], | ||
text: 'All men are mortal', | ||
}); | ||
expect(_createProposition).toHaveBeenCalledWith({ | ||
supportedBy: [], | ||
supports: [], | ||
text: 'All men are mortal', | ||
}); | ||
}); | ||
}); |
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,20 @@ | ||
import { | ||
createProposition as _createProposition, | ||
INewProposition, | ||
IProposition, | ||
} from '../../lib/proposition'; | ||
|
||
const DEFAULT_PROPS = { | ||
supportedBy: [], | ||
supports: [], | ||
}; | ||
|
||
/** | ||
* GraphQL resolver for the createProposition mutation. | ||
*/ | ||
export default async function createProposition( | ||
_: any, | ||
args: { text: string; supports?: number[]; supportedBy?: number[] } | ||
): Promise<IProposition> { | ||
return _createProposition({ ...DEFAULT_PROPS, ...args }); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
getProposition as _getProposition, | ||
IProposition, | ||
} from '../../lib/proposition'; | ||
|
||
/** | ||
* GraphQL resolver for the proposition field. | ||
*/ | ||
export default async function getProposition( | ||
_: any, | ||
{ id }: { id: number } | ||
): Promise<IProposition | void> { | ||
return _getProposition(id); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { importSchema } from 'graphql-import'; | ||
import { join } from 'path'; | ||
|
||
const typeDefs = importSchema(join(__dirname, './Query.graphql')); | ||
const typeDefs = importSchema(join(__dirname, './Root.graphql')); | ||
|
||
export default typeDefs; |
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