Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Stop using Team.plugins_opt_in #230

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getPluginRows(server: PluginsServer): Promise<Plugin[]> {
(SELECT posthog_pluginconfig.plugin_id
FROM posthog_pluginconfig
LEFT JOIN posthog_team ON posthog_team.id = posthog_pluginconfig.team_id
WHERE (posthog_team.id IS NULL OR posthog_team.plugins_opt_in='t') AND posthog_pluginconfig.enabled='t'
WHERE posthog_pluginconfig.enabled='t'
GROUP BY posthog_pluginconfig.plugin_id)`
)
return pluginRows
Expand All @@ -18,7 +18,7 @@ export async function getPluginAttachmentRows(server: PluginsServer): Promise<Pl
(SELECT posthog_pluginconfig.id
FROM posthog_pluginconfig
LEFT JOIN posthog_team ON posthog_team.id = posthog_pluginconfig.team_id
WHERE (posthog_team.id IS NULL OR posthog_team.plugins_opt_in='t') AND posthog_pluginconfig.enabled='t')`
WHERE posthog_pluginconfig.enabled='t')`
)
return rows
}
Expand All @@ -28,7 +28,7 @@ export async function getPluginConfigRows(server: PluginsServer): Promise<Plugin
`SELECT posthog_pluginconfig.*
FROM posthog_pluginconfig
LEFT JOIN posthog_team ON posthog_team.id = posthog_pluginconfig.team_id
WHERE (posthog_team.id IS NULL OR posthog_team.plugins_opt_in='t') AND posthog_pluginconfig.enabled='t'`
WHERE posthog_pluginconfig.enabled='t'`
)
return rows
}
Expand Down
30 changes: 21 additions & 9 deletions tests/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ afterEach(async () => {

test('getPluginAttachmentRows', async () => {
const rows1 = await getPluginAttachmentRows(server)
expect(rows1).toEqual([

const rowsExpected = [
{
content_type: 'application/octet-stream',
contents: Buffer.from([116, 101, 115, 116]),
Expand All @@ -27,16 +28,20 @@ test('getPluginAttachmentRows', async () => {
plugin_config_id: 39,
team_id: 2,
},
])
]
expect(rows1).toEqual(rowsExpected)

await server.db.postgresQuery("update posthog_team set plugins_opt_in='f'")
const rows2 = await getPluginAttachmentRows(server)
expect(rows2).toEqual([])

expect(rows2).toEqual(rowsExpected)
})

test('getPluginConfigRows', async () => {
await resetTestDatabase(`const processEvent = event => event`)
const rows1 = await getPluginConfigRows(server)
expect(rows1).toEqual([

const rowsExpected = [
{
config: {
localhostIP: '94.224.212.175',
Expand All @@ -48,16 +53,20 @@ test('getPluginConfigRows', async () => {
plugin_id: 60,
team_id: 2,
},
])
]
expect(rows1).toEqual(rowsExpected)

await server.db.postgresQuery("update posthog_team set plugins_opt_in='f'")
const rows2 = await getPluginConfigRows(server)
expect(rows2).toEqual([])

expect(rows2).toEqual(rowsExpected)
})

test('getPluginRows', async () => {
await resetTestDatabase(`const processEvent = event => event`)
const rows1 = await getPluginRows(server)
expect(rows1).toEqual([

const rowsExpected = [
{
archive: expect.any(Buffer),
config_schema: {
Expand Down Expand Up @@ -93,10 +102,13 @@ test('getPluginRows', async () => {
tag: '0.0.2',
url: 'https://www.npmjs.com/package/posthog-maxmind-plugin',
},
])
]
expect(rows1).toEqual(rowsExpected)

await server.db.postgresQuery("update posthog_team set plugins_opt_in='f'")
const rows2 = await getPluginRows(server)
expect(rows2).toEqual([])

expect(rows2).toEqual(rowsExpected)
})

test('setError', async () => {
Expand Down