Skip to content

Commit

Permalink
Finish muteword tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pfrazee committed Mar 9, 2024
1 parent 1fd25c2 commit 7452bb0
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 36 deletions.
4 changes: 4 additions & 0 deletions packages/api/src/mocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ const FAKE_CID = 'bafyreiclp443lavogvhj3d2ob2cxbfuscni2k5jk7bebjzg7khl3esabwq'
export const mock = {
post({
text,
facets,
reply,
embed,
}: {
text: string
facets?: AppBskyFeedPost.Record['facets']
reply?: AppBskyFeedPost.ReplyRef
embed?: AppBskyFeedPost.Record['embed']
}): AppBskyFeedPost.Record {
return {
$type: 'app.bsky.feed.post',
text,
facets,
reply,
embed,
langs: ['en'],
Expand Down Expand Up @@ -50,6 +53,7 @@ export const mock = {
labels?: ComAtprotoLabelDefs.Label[]
}): AppBskyFeedDefs.PostView {
return {
$type: 'app.bsky.feed.defs#postView',
uri: `at://${author.did}/app.bsky.feed.post/fake`,
cid: FAKE_CID,
author,
Expand Down
111 changes: 75 additions & 36 deletions packages/api/tests/moderation-mutewords.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RichText } from '../src/'
import { RichText, mock, moderatePost } from '../src/'

import { hasMutedWord } from '../src/moderation/mutewords'

Expand Down Expand Up @@ -602,51 +602,90 @@ describe(`hasMutedWord`, () => {
})
})

// TODO
describe.skip(`doesn't mute own post`, () => {
describe(`doesn't mute own post`, () => {
it(`does mute if it isn't own post`, () => {
const rt = new RichText({
text: `Mute words!`,
})

const match = hasMutedWord({
mutedWords: [{ value: 'words', targets: ['content'] }],
text: rt.text,
facets: rt.facets,
outlineTags: [],
})

expect(match).toBe(true)
const res = moderatePost(
mock.postView({
record: mock.post({
text: 'Mute words!',
}),
author: mock.profileViewBasic({
handle: 'bob.test',
displayName: 'Bob',
}),
labels: [],
}),
{
userDid: 'did:web:alice.test',
prefs: {
adultContentEnabled: false,
labels: {},
labelers: [],
mutedWords: [{ value: 'words', targets: ['content'] }],
hiddenPosts: [],
},
labelDefs: {},
},
)
expect(res.causes[0].type).toBe('mute-word')
})

it(`doesn't mute own post when muted word is in text`, () => {
const rt = new RichText({
text: `Mute words!`,
})

const match = hasMutedWord({
mutedWords: [{ value: 'words', targets: ['content'] }],
text: rt.text,
facets: rt.facets,
outlineTags: [],
})

expect(match).toBe(false)
const res = moderatePost(
mock.postView({
record: mock.post({
text: 'Mute words!',
}),
author: mock.profileViewBasic({
handle: 'bob.test',
displayName: 'Bob',
}),
labels: [],
}),
{
userDid: 'did:web:bob.test',
prefs: {
adultContentEnabled: false,
labels: {},
labelers: [],
mutedWords: [{ value: 'words', targets: ['content'] }],
hiddenPosts: [],
},
labelDefs: {},
},
)
expect(res.causes.length).toBe(0)
})

it(`doesn't mute own post when muted word is in tags`, () => {
const rt = new RichText({
text: `Mute #words!`,
})

const match = hasMutedWord({
mutedWords: [{ value: 'words', targets: ['tags'] }],
text: rt.text,
facets: rt.facets,
outlineTags: [],
})

expect(match).toBe(false)
const res = moderatePost(
mock.postView({
record: mock.post({
text: rt.text,
facets: rt.facets,
}),
author: mock.profileViewBasic({
handle: 'bob.test',
displayName: 'Bob',
}),
labels: [],
}),
{
userDid: 'did:web:bob.test',
prefs: {
adultContentEnabled: false,
labels: {},
labelers: [],
mutedWords: [{ value: 'words', targets: ['tags'] }],
hiddenPosts: [],
},
labelDefs: {},
},
)
expect(res.causes.length).toBe(0)
})
})
})

0 comments on commit 7452bb0

Please sign in to comment.