Skip to content

Commit

Permalink
feat(channels): disable legacy channels by default (#365)
Browse files Browse the repository at this point in the history
* feat(channels): disable legacy channels by default

* fix tests
  • Loading branch information
samuelmasse committed Feb 16, 2022
1 parent da24263 commit aae6946
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/channels/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ChannelService extends Service {
new VonageChannel()
]

if (!yn(process.env.DISABLE_LEGACY_CHANNELS)) {
if (yn(process.env.ENABLE_LEGACY_CHANNELS)) {
this.channels = [
...this.channels,
new MessengerChannelLegacy(),
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type MessagingEnv = EngineEnv & {
TWILIO_TESTING?: string
BILLING_ENDPOINT?: string
DISABLE_SOCKETS?: string
ENABLE_LEGACY_CHANNELS?: string
}

declare global {
Expand Down
11 changes: 5 additions & 6 deletions packages/server/test/integration/conduits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Conduits', () => {

state = {
provider: await app.providers.create(randStr(), false),
channel: app.channels.getByNameAndVersion('telegram', '0.1.0'),
channel: app.channels.getByNameAndVersion('telegram', '1.0.0'),
channelConfig: { botToken: randStr() }
}
})
Expand Down Expand Up @@ -109,15 +109,15 @@ describe('Conduits', () => {
test('List conduits by provider', async () => {
const conduit1 = await conduits.create(
state.provider.id,
app.channels.getByNameAndVersion('twilio', '0.1.0').meta.id,
app.channels.getByNameAndVersion('twilio', '1.0.0').meta.id,
{
accountSID: randStr(),
authToken: randStr()
}
)
const conduit2 = await conduits.create(
state.provider.id,
app.channels.getByNameAndVersion('teams', '0.1.0').meta.id,
app.channels.getByNameAndVersion('teams', '1.0.0').meta.id,
{
appId: randStr(),
appPassword: randStr()
Expand All @@ -127,11 +127,10 @@ describe('Conduits', () => {
const otherProvider = await app.providers.create(randStr(), false)
const conduit3 = await conduits.create(
otherProvider.id,
app.channels.getByNameAndVersion('slack', '0.1.0').meta.id,
app.channels.getByNameAndVersion('slack', '1.0.0').meta.id,
{
botToken: randStr(),
signingSecret: randStr(),
useRTM: false
signingSecret: randStr()
}
)

Expand Down
4 changes: 3 additions & 1 deletion packages/server/test/integration/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ describe('Health', () => {
const client = await app.clients.create(provider.id)
const conduit = await app.conduits.create(
provider.id,
app.channels.getByNameAndVersion(TEST_CHANNEL, '0.1.0').meta.id,
app.channels.getByNameAndVersion(TEST_CHANNEL, '1.0.0').meta.id,
{
appId: randStr(),
pageId: randStr(),
accessToken: randStr(),
appSecret: randStr(),
verifyToken: randStr()
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/integration/mapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('Mapping', () => {
await setupApp()
mapping = app.mapping
clientId = (await app.clients.create(undefined!)).id
channelId = app.channels.getByNameAndVersion('telegram', '0.1.0').meta.id
channelId2 = app.channels.getByNameAndVersion('twilio', '0.1.0').meta.id
channelId = app.channels.getByNameAndVersion('telegram', '1.0.0').meta.id
channelId2 = app.channels.getByNameAndVersion('twilio', '1.0.0').meta.id
})

afterAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/integration/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ describe('Status', () => {
await setupApp()

const provider = await app.providers.create(randStr(), false)
const channel = app.channels.getByNameAndVersion('twilio', '0.1.0')
const channel = app.channels.getByNameAndVersion('twilio', '1.0.0')
const conduit = await app.conduits.create(provider.id, channel.meta.id, { accountSID: 'abc', authToken: 'sds' })
const channel2 = app.channels.getByNameAndVersion('slack', '0.1.0')
const channel2 = app.channels.getByNameAndVersion('slack', '1.0.0')
const conduit2 = await app.conduits.create(provider.id, channel2.meta.id, { botToken: 'abc', signingSecret: 'sds' })

status = app.status
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/migration/0.1.19-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let STATUS_TABLE: string
const CONDUITS_INITIALIZED = 'initialized'
const STATUS_TEST_COLUMN = 'initializedOn'

const TELEGRAM_CHANNEL_ID = '0198f4f5-6100-4549-92e5-da6cc31b4ad1'
const TELEGRAM_CHANNEL_ID = 'e578723f-ab57-463c-bc13-b483db9bf547'

describe('0.1.19 - Status', () => {
let migration: MigrationService
Expand Down
39 changes: 16 additions & 23 deletions packages/server/test/unit/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,45 @@ jest.mock('@botpress/messaging-engine')

const channels = {
messenger: {
accessToken: 'accessToken',
version: '1.0.0',
appId: 'appId',
appSecret: 'appSecret',
verifyToken: 'verifyToken'
verifyToken: 'verifyToken',
pageId: 'pageId',
accessToken: 'accessToken'
},
slack: {
version: '1.0.0',
signingSecret: 'signingSecret',
useRTM: false,
botToken: 'botToken'
},
smooch: {
version: '1.0.0',
appId: 'appId',
keyId: 'keyId',
secret: 'secret',
forwardRawPayloads: ['text']
keySecret: 'keySecret',
webhookSecret: 'webhookSecret'
},
teams: {
version: '1.0.0',
appId: 'appId',
appPassword: 'appPassword',
proactiveMessages: {
proactiveMessages: 'proactiveMessages'
}
appPassword: 'appPassword'
},
telegram: {
version: '1.0.0',
botToken: 'botToken'
},
twilio: {
version: '1.0.0',
accountSID: 'accountSID',
authToken: 'authToken'
},
vonage: {
useTestingApi: true,
version: '1.0.0',
apiKey: 'apiKey',
apiSecret: 'apiSecret',
signatureSecret: 'signatureSecret',
applicationId: 'applicationId',
privateKey: 'privateKey'
useTestingApi: true
}
}

Expand Down Expand Up @@ -72,16 +76,5 @@ describe('Sync', () => {

expect(value).toEqual({ channels, webhooks: [] })
})

test('Should strip unknown properties from legacy channels', async () => {
const { error, value } = syncApi.validate({
channels: { ...channels, telegram: { ...channels.telegram, randomProp: 'yoyo' } }
})
if (error) {
throw error
}

expect(value).toEqual({ channels, webhooks: [] })
})
})
})

0 comments on commit aae6946

Please sign in to comment.