-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into zod-feed-cleanup
- Loading branch information
Showing
16 changed files
with
751 additions
and
29 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 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
SELECT | ||
-- Thread details (DbThreadType) | ||
thread_external_id as thread_id, | ||
board_slug, | ||
board_external_id as board_id, | ||
realm_slug, | ||
realm_external_id as realm_id, | ||
TO_CHAR(last_update_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS.00"Z') as thread_last_activity_at, | ||
thread_details.default_view, | ||
-- Amount details | ||
COALESCE(posts_amount, 0) as thread_total_posts_amount, | ||
COALESCE(threads_amount, 0) as thread_direct_threads_amount, | ||
COALESCE(comments_amount, 0) as thread_total_comments_amount, | ||
COALESCE(new_posts_board_amount, 0) as thread_new_posts_amount, | ||
COALESCE(new_comments_board_amount, 0) as thread_new_comments_amount, | ||
COALESCE(muted, FALSE) as muted, | ||
COALESCE(hidden, FALSE) as hidden, | ||
COALESCE(starred, FALSE) as starred, | ||
-- Contribution details (DbContributionType) | ||
first_post_string_id as post_id, | ||
thread_external_id as parent_thread_id, | ||
NULL as parent_post_id, | ||
board_slug as parent_board_slug, | ||
board_external_id as parent_board_id, | ||
-- Author details | ||
author, | ||
username, | ||
user_avatar, | ||
secret_identity_name, | ||
secret_identity_avatar, | ||
secret_identity_color, | ||
accessory_avatar, | ||
COALESCE(friend_thread, FALSE) as friend, | ||
COALESCE(own_thread, FALSE) as self, | ||
TO_CHAR(first_post_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS.00"Z"') as created_at, | ||
-- Generic details | ||
content, | ||
-- Contribution tags | ||
index_tags, | ||
category_tags, | ||
content_warnings, | ||
whisper_tags, | ||
COALESCE(own_thread, FALSE) as is_own, | ||
COALESCE(is_new_board, FALSE) as is_new, | ||
-- This last activity must have the .US at the end or it will trigger a bug | ||
-- where some posts are skipped by the last activity cursor. | ||
-- See documentation on the queries JS file. | ||
TO_CHAR(last_update_timestamp, 'YYYY-MM-DD"T"HH24:MI:SS.US') as thread_last_activity_at_micro | ||
FROM threads | ||
INNER JOIN thread_details | ||
ON threads.id = thread_details.thread_id AND thread_details.realm_external_id = ${realm_id} | ||
LEFT JOIN thread_identities | ||
ON thread_identities.user_id = thread_details.author AND thread_identities.thread_id = thread_details.thread_id | ||
LEFT JOIN thread_user_details | ||
ON ${firebase_id} IS NOT NULL AND thread_user_details.user_id = (SELECT id FROM users WHERE users.firebase_id = ${firebase_id} LIMIT 1) | ||
AND thread_details.thread_id = thread_user_details.thread_id | ||
WHERE | ||
-- Activity cursor conditions | ||
thread_details.realm_external_id = ${realm_id} | ||
AND last_update_timestamp <= COALESCE(${last_activity_cursor}, NOW()) | ||
AND is_new IS TRUE | ||
AND muted IS FALSE | ||
AND hidden IS FALSE | ||
ORDER BY thread_last_activity_at DESC | ||
LIMIT ${page_size} + 1 |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { BOBATAN_USER_ID, ONCEST_USER_ID } from "test/data/auth"; | ||
import { setLoggedInUser, startTestServer } from "utils/test-utils"; | ||
|
||
import { BOBATAN_REALM_FEED } from "test/data/realmfeed"; | ||
import { TWISTED_MINDS_REALM_EXTERNAL_ID } from "test/data/realms"; | ||
import debug from "debug"; | ||
import request from "supertest"; | ||
import router from "../../routes"; | ||
|
||
jest.mock("handlers/auth"); | ||
|
||
const log = debug("bobaserver:board:routes"); | ||
|
||
describe("Tests Realm Activity Feed Endpoint", () => { | ||
const server = startTestServer(router); | ||
|
||
test("should return realm activity data" , async () => { | ||
setLoggedInUser(BOBATAN_USER_ID) | ||
const res = await request(server.app).get(`/realms/${TWISTED_MINDS_REALM_EXTERNAL_ID}`); | ||
|
||
expect(res.status).toBe(200); | ||
expect(res.body).toEqual(BOBATAN_REALM_FEED); | ||
}); | ||
|
||
test("should return 401 when user isn't logged in", async () => { | ||
const res = await request(server.app).get(`/realms/${TWISTED_MINDS_REALM_EXTERNAL_ID}`); | ||
|
||
expect(res.status).toBe(401); | ||
expect(res.body).toEqual({message: "No authenticated user 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
Oops, something went wrong.