Discourse: scope mirror tests as being "mode 1" (#1463)
This is to prepare for mode 2 being tested side-by-side. The normalizeMode1Topics function enforces bumpedMs is not updated for mode 1 tests. Additionally describe "update semantics" is redundant, as the mirror has no other function than update.
This commit is contained in:
parent
3ceb4fb7fa
commit
c521acc145
|
@ -169,6 +169,14 @@ class MockFetcher implements Discourse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeMode1Topics(topics: Topic[]): Topic[] {
|
||||||
|
return topics.map((topic) => ({
|
||||||
|
...topic,
|
||||||
|
// Mode 1 didn't support bumpMs handling.
|
||||||
|
bumpedMs: topic.timestampMs,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
describe("plugins/discourse/mirror", () => {
|
describe("plugins/discourse/mirror", () => {
|
||||||
function spyWarn(): JestMockFn<[string], void> {
|
function spyWarn(): JestMockFn<[string], void> {
|
||||||
return ((console.warn: any): JestMockFn<any, void>);
|
return ((console.warn: any): JestMockFn<any, void>);
|
||||||
|
@ -201,6 +209,7 @@ describe("plugins/discourse/mirror", () => {
|
||||||
return {fetcher, mirror, reporter, url, repo};
|
return {fetcher, mirror, reporter, url, repo};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe("mirror mode 1", () => {
|
||||||
it("mirrors topics from the fetcher", async () => {
|
it("mirrors topics from the fetcher", async () => {
|
||||||
const {mirror, fetcher, reporter, repo} = example();
|
const {mirror, fetcher, reporter, repo} = example();
|
||||||
fetcher.addPost(2, null);
|
fetcher.addPost(2, null);
|
||||||
|
@ -208,7 +217,7 @@ describe("plugins/discourse/mirror", () => {
|
||||||
const topic2 = fetcher._topic(2);
|
const topic2 = fetcher._topic(2);
|
||||||
const topic3 = fetcher._topic(3);
|
const topic3 = fetcher._topic(3);
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
expect(repo.topics()).toEqual([topic2, topic3]);
|
expect(repo.topics()).toEqual(normalizeMode1Topics([topic2, topic3]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("mirrors posts from the fetcher", async () => {
|
it("mirrors posts from the fetcher", async () => {
|
||||||
|
@ -273,7 +282,6 @@ describe("plugins/discourse/mirror", () => {
|
||||||
expect(repo.likes()).toEqual([]);
|
expect(repo.likes()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("update semantics", () => {
|
|
||||||
it("only fetches new topics on `update`", async () => {
|
it("only fetches new topics on `update`", async () => {
|
||||||
const {mirror, fetcher, reporter, repo} = example();
|
const {mirror, fetcher, reporter, repo} = example();
|
||||||
fetcher.addPost(1, null);
|
fetcher.addPost(1, null);
|
||||||
|
@ -420,7 +428,7 @@ describe("plugins/discourse/mirror", () => {
|
||||||
// Force the fetcher not to return topic 2
|
// Force the fetcher not to return topic 2
|
||||||
fetcher._latestTopicId--;
|
fetcher._latestTopicId--;
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
const topics = [fetcher._topic(1)];
|
const topics = normalizeMode1Topics([fetcher._topic(1)]);
|
||||||
expect(repo.topics()).toEqual(topics);
|
expect(repo.topics()).toEqual(topics);
|
||||||
const posts = [fetcher._post(pid1)];
|
const posts = [fetcher._post(pid1)];
|
||||||
expect(repo.posts()).toEqual(posts);
|
expect(repo.posts()).toEqual(posts);
|
||||||
|
@ -443,7 +451,7 @@ describe("plugins/discourse/mirror", () => {
|
||||||
// Force the fetcher not to return topic 2
|
// Force the fetcher not to return topic 2
|
||||||
fetcher._latestTopicId--;
|
fetcher._latestTopicId--;
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
const topics = [fetcher._topic(1)];
|
const topics = normalizeMode1Topics([fetcher._topic(1)]);
|
||||||
expect(repo.topics()).toEqual(topics);
|
expect(repo.topics()).toEqual(topics);
|
||||||
const posts = [pid1, pid3].map((x) => fetcher._post(x));
|
const posts = [pid1, pid3].map((x) => fetcher._post(x));
|
||||||
expect(repo.posts()).toEqual(posts);
|
expect(repo.posts()).toEqual(posts);
|
||||||
|
@ -461,7 +469,8 @@ describe("plugins/discourse/mirror", () => {
|
||||||
const badLike = {username: "credbot", postId: 37, timestampMs: 0};
|
const badLike = {username: "credbot", postId: 37, timestampMs: 0};
|
||||||
fetcher._likes.push(badLike);
|
fetcher._likes.push(badLike);
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
expect(repo.topics()).toEqual([fetcher._topic(1)]);
|
const topics = normalizeMode1Topics([fetcher._topic(1)]);
|
||||||
|
expect(repo.topics()).toEqual(topics);
|
||||||
expect(repo.posts()).toEqual([fetcher._post(pid)]);
|
expect(repo.posts()).toEqual([fetcher._post(pid)]);
|
||||||
expect(repo.likes()).toEqual([]);
|
expect(repo.likes()).toEqual([]);
|
||||||
expect(console.warn).toHaveBeenCalledWith(
|
expect(console.warn).toHaveBeenCalledWith(
|
||||||
|
@ -471,14 +480,13 @@ describe("plugins/discourse/mirror", () => {
|
||||||
expect(console.warn).toHaveBeenCalledTimes(1);
|
expect(console.warn).toHaveBeenCalledTimes(1);
|
||||||
spyWarn().mockReset();
|
spyWarn().mockReset();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it("warns if a user's likes are missing", async () => {
|
it("warns if a user's likes are missing", async () => {
|
||||||
const {mirror, fetcher, reporter, repo} = example();
|
const {mirror, fetcher, reporter, repo} = example();
|
||||||
const pid = fetcher.addPost(1, null, "credbot");
|
const pid = fetcher.addPost(1, null, "credbot");
|
||||||
(fetcher: any).likesByUser = async () => null;
|
(fetcher: any).likesByUser = async () => null;
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
expect(repo.topics()).toEqual([fetcher._topic(1)]);
|
expect(repo.topics()).toEqual(normalizeMode1Topics([fetcher._topic(1)]));
|
||||||
expect(repo.posts()).toEqual([fetcher._post(pid)]);
|
expect(repo.posts()).toEqual([fetcher._post(pid)]);
|
||||||
expect(repo.likes()).toEqual([]);
|
expect(repo.likes()).toEqual([]);
|
||||||
});
|
});
|
||||||
|
@ -497,7 +505,7 @@ describe("plugins/discourse/mirror", () => {
|
||||||
return await _likesByUser(targetUsername, offset);
|
return await _likesByUser(targetUsername, offset);
|
||||||
};
|
};
|
||||||
await mirror.update(reporter);
|
await mirror.update(reporter);
|
||||||
expect(repo.topics()).toEqual([fetcher._topic(1)]);
|
expect(repo.topics()).toEqual(normalizeMode1Topics([fetcher._topic(1)]));
|
||||||
expect(repo.posts()).toEqual([fetcher._post(p1), fetcher._post(p2)]);
|
expect(repo.posts()).toEqual([fetcher._post(p1), fetcher._post(p2)]);
|
||||||
expect(repo.likes()).toEqual([l1]);
|
expect(repo.likes()).toEqual([l1]);
|
||||||
});
|
});
|
||||||
|
@ -560,3 +568,4 @@ describe("plugins/discourse/mirror", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue