Skip to content

Commit 8e6c0f3

Browse files
committed
chore: upgrade to v3.0.0 and add compatibility with new WhatsMeow provider
This commit updates the codebase to align with version v3.0.0 and introduces support for a new WhatsMeow provider. A compatible adapter is required and is available at: https://github.com/mbap-dev/provider-whatsmeow
1 parent 37a3673 commit 8e6c0f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1095
-621
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ data/medias/*
77
data/stores/*
88
data/sessions/*
99
.env
10+
.idea/*
11+
1012
.yarn/*
1113
.yarnrc.yml

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nodejs 24.7.0
2+
yarn 1.22.22

__tests__/jobs/timer.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const delLastTimerMock = delLastTimer as jest.MockedFunction<typeof delLastTimer
77

88
describe('timer', () => {
99
let incoming, job, payload, phone, to, message, time, sendSpy, mockGetLastTimer, incomingPayload
10-
10+
1111
beforeEach(() => {
1212
incoming = mock<Incoming>()
1313
mockGetLastTimer = jest.fn()
@@ -17,21 +17,24 @@ describe('timer', () => {
1717
message = `${new Date().getTime()}s sdfhosfo`
1818
time = '2011-10-05T14:48:00.000Z'
1919
payload = {
20-
phone, to, message, time
20+
phone,
21+
to,
22+
message,
23+
time,
2124
}
2225
sendSpy = jest.spyOn(incoming, 'send')
2326

24-
incomingPayload =[
27+
incomingPayload = [
2528
phone,
2629
{
2730
messaging_product: 'whatsapp',
2831
to,
2932
type: 'text',
3033
text: {
31-
body: message
32-
}
34+
body: message,
35+
},
3336
},
34-
{}
37+
{},
3538
]
3639
delLastTimerMock.mockResolvedValue(Promise.resolve())
3740
})

__tests__/routes/blacklist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe('blacklist routes', () => {
2424
const reload = mock<Reload>()
2525
const logout = mock<Logout>()
2626
const app: App = new App(incoming, outgoing, '', getConfigTest, sessionStore, onNewLogin, addToBlacklist, reload, logout)
27-
const res = await request(app.server).post('/2/blacklist/1').send({ttl: 1, to: '3'})
28-
expect(addToBlacklist).toHaveBeenCalledWith('2', '1', '3', 1);
27+
const res = await request(app.server).post('/2/blacklist/1').send({ ttl: 1, to: '3' })
28+
expect(addToBlacklist).toHaveBeenCalledWith('2', '1', '3', 1)
2929
expect(res.status).toEqual(200)
3030
})
3131
})

__tests__/services/blacklist.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
jest.mock('../../src/services/redis')
32
import { isInBlacklistInMemory, addToBlacklistInMemory, cleanBlackList, isInBlacklistInRedis } from '../../src/services/blacklist'
43
import { redisGet, redisKeys, blacklist } from '../../src/services/redis'

__tests__/services/media_store_file.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const phone = `${new Date().getTime()}`
88
const messageId = `wa.${new Date().getTime()}`
99
const url = `http://somehost`
1010
const mimetype = 'text/plain'
11-
const extension = 'txt'
11+
const extension = 'txt'
1212

1313
const message = {
1414
messaging_product: 'whatsapp',
1515
id: `${phone}/${messageId}`,
16-
mime_type: mimetype
16+
mime_type: mimetype,
1717
}
1818
const dataStore = mock<DataStore>()
1919
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -25,15 +25,36 @@ describe('media routes', () => {
2525
let mediaStore: MediaStore
2626

2727
beforeEach(() => {
28-
dataStore.loadMediaPayload.mockReturnValue(new Promise((resolve) => resolve(message)))
28+
dataStore.loadMediaPayload.mockReset()
2929
mediaStore = getMediaStoreFile(phone, defaultConfig, getTestDataStore)
3030
})
3131

3232
test('getMedia', async () => {
33+
dataStore.loadMediaPayload.mockResolvedValueOnce(message)
3334
const response = {
3435
url: `${url}/v15.0/download/${phone}/${messageId}.${extension}`,
35-
...message
36+
...message,
3637
}
3738
expect(await mediaStore.getMedia(url, messageId)).toStrictEqual(response)
3839
})
40+
41+
test('getMedia without mime type', async () => {
42+
const payload = {
43+
messaging_product: 'whatsapp',
44+
id: `${phone}/${messageId}`,
45+
filename: `${messageId}.${extension}`,
46+
}
47+
dataStore.loadMediaPayload.mockResolvedValueOnce(payload)
48+
const response = {
49+
url: `${url}/v15.0/download/${phone}/${messageId}.${extension}`,
50+
...payload,
51+
mime_type: mimetype,
52+
}
53+
expect(await mediaStore.getMedia(url, messageId)).toStrictEqual(response)
54+
})
55+
56+
test('getMedia not found', async () => {
57+
dataStore.loadMediaPayload.mockResolvedValueOnce(undefined)
58+
expect(await mediaStore.getMedia(url, messageId)).toBeUndefined()
59+
})
3960
})

__tests__/services/outgoing_cloud_api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('service outgoing whatsapp cloud api', () => {
4949
service = new OutgoingCloudApi(getConfig, isInBlacklistMock, addToBlacklistMock)
5050
textPayload = {
5151
text: {
52-
body: 'test'
52+
body: 'test',
5353
},
5454
type: 'text',
5555
to: 'abc',
@@ -63,8 +63,8 @@ describe('service outgoing whatsapp cloud api', () => {
6363
value: {
6464
contacts: [{ wa_id }],
6565
metadata: { display_phone_number: 'abc' },
66-
messages: [ { from: 'abc' }, ]
67-
}
66+
messages: [{ from: 'abc' }],
67+
},
6868
},
6969
],
7070
},
@@ -77,7 +77,7 @@ describe('service outgoing whatsapp cloud api', () => {
7777
changes: [
7878
{
7979
value: {
80-
statuses: [ { status: 'deleted' } ]
80+
statuses: [{ status: 'deleted' }],
8181
},
8282
},
8383
],

__tests__/services/session_store_file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('service session store file', () => {
3838
return MAX_CONNECT_RETRY + 1
3939
}
4040
return getConnectCount(session)
41-
}
41+
}
4242
expect(await store.verifyStatusStandBy(session)).toBe(true)
4343
})
4444
test('return a no standby on count and verify', async () => {
@@ -50,7 +50,7 @@ describe('service session store file', () => {
5050
return MAX_CONNECT_RETRY - 2
5151
}
5252
return getConnectCount(session)
53-
}
54-
expect(!!await store.verifyStatusStandBy(session)).toBe(false)
53+
}
54+
expect(!!(await store.verifyStatusStandBy(session))).toBe(false)
5555
})
5656
})

__tests__/services/socket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('service socket', () => {
4949
onNewLogin,
5050
attempts: 1,
5151
time: 1,
52-
config: { ...defaultConfig, whatsappVersion }
52+
config: { ...defaultConfig, whatsappVersion },
5353
})
5454
expect(response && response.status.attempt).toBe(1)
5555
})
@@ -65,7 +65,7 @@ describe('service socket', () => {
6565
onNewLogin,
6666
attempts: 1,
6767
time: 1,
68-
config: { ...defaultConfig, whatsappVersion }
68+
config: { ...defaultConfig, whatsappVersion },
6969
})
7070
expect(mockOn).toHaveBeenCalled()
7171
})

0 commit comments

Comments
 (0)