Skip to content

Commit

Permalink
Merge pull request #342 from cofacts/strict-schema
Browse files Browse the repository at this point in the history
Disable dynamic ES mapping and fix test fixtures
  • Loading branch information
MrOrz authored Nov 1, 2024
2 parents 7b2d03a + 55b5710 commit 136c93e
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 178 deletions.
1 change: 0 additions & 1 deletion src/__fixtures__/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default {
'/users/doc/test-user': {
id: 'test-user',
name: 'test user',
email: '[email protected]',
facebookId: 'secret-fb-id',
Expand Down
2 changes: 0 additions & 2 deletions src/graphql/dataLoaders/__fixtures__/userLoaderFactory.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
export default {
'/users/doc/test-user': {
id: 'test-user',
slug: 'abc123',
name: 'test user',
email: '[email protected]',
},
'/users/doc/test-user2': {
id: 'test-user2',
slug: 'def456',
name: 'test user2',
email: '[email protected]',
Expand Down
1 change: 0 additions & 1 deletion src/graphql/mutations/CreateArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ async function createNewArticle({ text, reference: originalReference, user }) {
normalArticleReplyCount: 0,
normalArticleCategoryCount: 0,
replyRequestCount: 0,
tags: [],
hyperlinks: [],
articleType: 'TEXT',
attachmentUrl: '',
Expand Down
8 changes: 6 additions & 2 deletions src/graphql/mutations/CreateMediaArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ async function createNewMediaArticle({
normalArticleReplyCount: 0,
normalArticleCategoryCount: 0,
replyRequestCount: 0,
tags: [],
hyperlinks: [],
articleType,
attachmentHash,
Expand Down Expand Up @@ -288,7 +287,12 @@ export default {
})
// It's OK to fail this promise, just log as warning
.catch((e) =>
console.warn(`[CreateMediaArticle] ${mediaEntry.id}:`, e)
console.warn(
`[CreateMediaArticle] ${mediaEntry.id}:`,

// `meta` is provided by elasticsearch error response
'meta' in e ? e.meta : e
)
),
]);

Expand Down
18 changes: 4 additions & 14 deletions src/graphql/mutations/__fixtures__/UpdateUser.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
export default {
'/users/doc/error': {
users: [
{
name: 'Bill',
updatedAt: 0,
},
],
name: 'Bill',
updatedAt: 0,
},
'/users/doc/normal': {
users: [
{
name: 'Bill',
updatedAt: 0,
},
],
name: 'Bill',
updatedAt: 0,
},
'/users/doc/testUser1': {
id: 'testUser1',
name: 'test user 1',
facebookId: 'fbid123',
githubId: 'githubId123',
email: '[email protected]',
},
'/users/doc/testUser2': {
id: 'testUser2',
name: 'test user 2',
githubId: 'githubId456',
email: '[email protected]',
Expand Down
1 change: 0 additions & 1 deletion src/graphql/mutations/__tests__/CreateMediaArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe('creation', () => {
],
"replyRequestCount": 1,
"status": "NORMAL",
"tags": Array [],
"text": "OCR result of output image",
"updatedAt": "2017-01-28T08:45:57.011Z",
"userId": "test",
Expand Down
29 changes: 14 additions & 15 deletions src/graphql/mutations/__tests__/UpdateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import client from 'util/client';
import MockDate from 'mockdate';
import fixtures from '../__fixtures__/UpdateUser';

const testUser1 = fixtures['/users/doc/testUser1'];
const testUser2 = fixtures['/users/doc/testUser2'];

const updateUser = (variableString, userId) =>
Expand Down Expand Up @@ -75,77 +74,77 @@ describe('UpdateUser', () => {
it('should set user slug field correctly', async () => {
const { data, errors } = await updateUser(
`slug: "test-user-1"`,
testUser1.id
'testUser1'
);

expect(errors).toBe(undefined);
expect(data).toMatchSnapshot();

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

it('cannot set duplicated slug', async () => {
const { errors } = await updateUser(
`slug: "${testUser2.slug}"`,
testUser1.id
'testUser1'
);

expect(errors).toMatchSnapshot();

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

it('should set all provided fields correctly', async () => {
const { data, errors } = await updateUser(
`slug: "test-user-3", name: "new name", avatarType: Gravatar, bio: "blahblahblah"`,
testUser1.id
'testUser1'
);

expect(errors).toBe(undefined);
expect(data).toMatchSnapshot();

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

it('should not set unsupported fields', async () => {
const { errors } = await updateUser(
`email: "[email protected]"`,
testUser1.id
'testUser1'
);

expect(errors).toMatchSnapshot();

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

it('should not unset fields', async () => {
const { errors } = await updateUser(`slug: "", name: null`, testUser1.id);
const { errors } = await updateUser(`slug: "", name: null`, 'testUser1');

expect(errors).toMatchSnapshot();

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

it('should preserve avatarData field for non openpeeps avatar', async () => {
let { data, errors } = await updateUser(
`avatarData:"""{"key":"value"}""", avatarType: OpenPeeps`,
testUser1.id
'testUser1'
);
expect(errors).toBe(undefined);
expect(data).toMatchSnapshot('openpeeps');

({ data, errors } = await updateUser(`avatarType: Facebook`, testUser1.id));
({ data, errors } = await updateUser(`avatarType: Facebook`, 'testUser1'));
expect(errors).toBe(undefined);
expect(data).toMatchSnapshot('facebook');

({ data, errors } = await updateUser(
`avatarType: Github, avatarData:"""{"key":"123"}"""`,
testUser1.id
'testUser1'
));
expect(errors).toBe(undefined);
expect(data).toMatchSnapshot('github');

expect(await getUser(testUser1.id)).toMatchSnapshot();
expect(await getUser('testUser1')).toMatchSnapshot();
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Object {
],
"replyRequestCount": 1,
"status": "NORMAL",
"tags": Array [],
"text": "FOO FOO http://foo.com/article/1",
"updatedAt": "2017-01-28T08:45:57.011Z",
"userId": "test",
Expand Down
12 changes: 0 additions & 12 deletions src/graphql/mutations/__tests__/__snapshots__/UpdateUser.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "test user 1",
"slug": "test-user-1",
"updatedAt": "2020-01-01T00:00:10.000Z",
Expand All @@ -31,7 +30,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "new name",
"slug": "test-user-3",
"updatedAt": "2020-01-01T00:00:30.000Z",
Expand All @@ -51,7 +49,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "new name",
"slug": "test-user-3",
"updatedAt": "2020-01-01T00:00:30.000Z",
Expand All @@ -66,7 +63,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "new name",
"slug": "test-user-3",
"updatedAt": "2020-01-01T00:01:00.000Z",
Expand Down Expand Up @@ -140,7 +136,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "new name",
"slug": "test-user-3",
"updatedAt": "2020-01-01T00:00:30.000Z",
Expand All @@ -161,12 +156,6 @@ exports[`UpdateUser should set user name field correctly 2`] = `
Object {
"name": "Mark",
"updatedAt": "2020-01-01T00:00:00.000Z",
"users": Array [
Object {
"name": "Bill",
"updatedAt": 0,
},
],
}
`;

Expand All @@ -190,7 +179,6 @@ Object {
"email": "[email protected]",
"facebookId": "fbid123",
"githubId": "githubId123",
"id": "testUser1",
"name": "test user 1",
"slug": "test-user-1",
"updatedAt": "2020-01-01T00:00:10.000Z",
Expand Down
4 changes: 0 additions & 4 deletions src/graphql/queries/__fixtures__/GetUser.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
export default {
'/users/doc/test-user': {
id: 'test-user',
slug: 'abc123',
name: 'test user',
email: '[email protected]',
avatarType: 'Facebook',
facebookId: 123456,
},
'/users/doc/current-user': {
id: 'current-user',
slug: 'def456',
name: 'current user',
email: '[email protected]',
avatarType: 'Github',
githubId: 654321,
},
'/users/doc/test-email-user': {
id: 'test-email-user',
slug: 'ghi789',
name: 'test email user',
email: '[email protected]',
},
'/users/doc/another-user': {
id: 'another-user',
name: 'open peeps user',
email: '[email protected]',
avatarType: 'OpenPeeps',
Expand Down
2 changes: 0 additions & 2 deletions src/graphql/queries/__fixtures__/ListReplyRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ export default {
updatedAt: '2020-01-01T00:00:00.000Z',
},
'/users/doc/user1': {
id: 'user1',
appId: 'WEBSITE',
name: 'user 1',
},
'/users/doc/user2': {
id: 'user2',
appId: 'WEBSITE',
name: 'user 2',
},
Expand Down
1 change: 0 additions & 1 deletion src/graphql/queries/__fixtures__/ValidateSlug.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export default {
'/users/doc/test-user': {
id: 'test-user',
slug: 'taken',
name: 'test user',
email: '[email protected]',
Expand Down
10 changes: 8 additions & 2 deletions src/graphql/queries/__tests__/GetUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import gql from 'util/GraphQL';
import { loadFixtures, unloadFixtures } from 'util/fixtures';
import fixtures from '../__fixtures__/GetUser';

const currentUser = fixtures['/users/doc/current-user'];
const testEmailUser = fixtures['/users/doc/test-email-user'];
const currentUser = {
...fixtures['/users/doc/current-user'],
id: 'current-user',
};
const testEmailUser = {
...fixtures['/users/doc/test-email-user'],
id: 'test-email-user',
};
describe('GetUser', () => {
beforeAll(() => loadFixtures(fixtures));

Expand Down
2 changes: 1 addition & 1 deletion src/rumors-db
Loading

0 comments on commit 136c93e

Please sign in to comment.