-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathcompatibility.ts
159 lines (142 loc) · 3.82 KB
/
compatibility.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import {
disposeGraphQLTesting,
GraphQLTestClient,
GraphQLTestingState,
initializeGraphQLTesting,
MockContext,
saveFixtures,
} from './helpers';
import {
ArticlePost,
Bookmark,
Post,
PostKeyword,
Source,
User,
} from '../src/entity';
import { sourcesFixture } from './fixture/source';
import { postKeywordsFixture, postsFixture } from './fixture/post';
import { DataSource } from 'typeorm';
import createOrGetConnection from '../src/db';
import { usersFixture } from './fixture/user';
let con: DataSource;
let state: GraphQLTestingState;
let client: GraphQLTestClient;
let loggedUser: string = null;
beforeAll(async () => {
con = await createOrGetConnection();
state = await initializeGraphQLTesting(
() => new MockContext(con, loggedUser),
);
client = state.client;
});
beforeEach(async () => {
loggedUser = null;
await saveFixtures(con, Source, sourcesFixture);
await saveFixtures(con, ArticlePost, postsFixture);
await saveFixtures(con, PostKeyword, postKeywordsFixture);
});
afterAll(() => disposeGraphQLTesting(state));
const now = new Date();
const bookmarksFixture = [
{
userId: '1',
postId: 'p3',
createdAt: new Date(now.getTime() - 1000),
},
{
userId: '1',
postId: 'p1',
createdAt: new Date(now.getTime() - 2000),
},
{
userId: '1',
postId: 'p5',
createdAt: new Date(now.getTime() - 3000),
},
];
const feedFields = `
id
url
title
readTime
tags
publication {
id
name
image
}
`;
describe('query latest', () => {
const QUERY = `
query Latest($params: QueryPostInput) {
latest(params: $params) {
${feedFields}
}
}`;
it('should return anonymous feed with no filters ordered by popularity', async () => {
await con.getRepository(Post).delete({ id: 'p6' });
const latest = new Date().toISOString();
const res = await client.query(QUERY, {
variables: { params: { latest } },
});
expect(res.data).toMatchSnapshot();
});
it('should return anonymous feed with no filters ordered by time', async () => {
await con.getRepository(Post).delete({ id: 'p6' });
const latest = new Date().toISOString();
const res = await client.query(QUERY, {
variables: { params: { latest, sortBy: 'creation' } },
});
expect(res.data).toMatchSnapshot();
});
it('should return anonymous feed filtered by sources', async () => {
const latest = new Date().toISOString();
const res = await client.query(QUERY, {
variables: { params: { latest, pubs: 'a,b' } },
});
expect(res.data).toMatchSnapshot();
});
it('should return anonymous feed filtered by tags', async () => {
const latest = new Date().toISOString();
const res = await client.query(QUERY, {
variables: { params: { latest, tags: 'html,webdev' } },
});
expect(res.data).toMatchSnapshot();
});
});
describe('query bookmarks', () => {
const QUERY = `
query Bookmarks($params: QueryPostInput) {
bookmarks(params: $params) {
${feedFields}
}
}`;
beforeEach(async () => {
await saveFixtures(con, User, usersFixture);
});
it('should return bookmarks ordered by time', async () => {
const latest = new Date().toISOString();
loggedUser = '1';
await saveFixtures(con, Bookmark, bookmarksFixture);
const res = await client.query(QUERY, {
variables: { params: { latest } },
});
expect(res.data).toMatchSnapshot();
});
});
describe('query postsByTag', () => {
const QUERY = `
query PostsByTag($params: PostByTagInput) {
postsByTag(params: $params) {
${feedFields}
}
}`;
it('should return a single tag feed', async () => {
const latest = new Date().toISOString();
const res = await client.query(QUERY, {
variables: { params: { latest, tag: 'javascript' } },
});
expect(res.data).toMatchSnapshot();
});
});