chore: cleanup, ci workflows and formatting (#127064)
* ci: setup workflows, dependabot, labeler and commit linting * docs: update README, community files and issue templates * chore: configure prettier, editorconfig and format codebase * chore: restore changes lost during rebase * docs: adjust url for new logo * fix: align badges * chore: resolve conflicts and re-add temp lint
This commit is contained in:
parent
c2d978fd0a
commit
807efd502d
94 changed files with 6790 additions and 3547 deletions
|
|
@ -1,14 +1,16 @@
|
|||
## Running tests
|
||||
# Running Tests
|
||||
|
||||
These tests require an authenticated WhatsApp Web session, as well as an additional phone that you can send messages to.
|
||||
|
||||
This can be configured using the following environment variables:
|
||||
- `WWEBJS_TEST_SESSION`: A JSON-formatted string with legacy auth session details. Must include `WABrowserId`, `WASecretBundle`, `WAToken1` and `WAToken2`.
|
||||
- `WWEBJS_TEST_SESSION_PATH`: Path to a JSON file that contains the legacy auth session details. Must include `WABrowserId`, `WASecretBundle`, `WAToken1` and `WAToken2`.
|
||||
- `WWEBJS_TEST_CLIENT_ID`: `clientId` to use for local file based authentication.
|
||||
- `WWEBJS_TEST_REMOTE_ID`: A valid WhatsApp ID that you can send messages to, e.g. `123456789@c.us`. It should be different from the ID used by the provided session.
|
||||
|
||||
You *must* set `WWEBJS_TEST_REMOTE_ID` **and** either `WWEBJS_TEST_SESSION`, `WWEBJS_TEST_SESSION_PATH` or `WWEBJS_TEST_CLIENT_ID` for the tests to run properly.
|
||||
- `WWEBJS_TEST_CLIENT_ID`: `clientId` to use for local file based authentication (required for authenticated tests).
|
||||
- `WWEBJS_TEST_REMOTE_ID`: A valid WhatsApp ID that you can send messages to, e.g. `123456789@c.us`. It should be different from the ID used by the provided session (required).
|
||||
|
||||
### Multidevice
|
||||
Some of the tested functionality depends on whether the account has multidevice enabled or not. If you are using multidevice, you should set `WWEBJS_TEST_MD=1`.
|
||||
You can create a `.env` file in the root directory with these variables. See `.env.example` for a template.
|
||||
|
||||
To run the tests:
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
|
|
|||
267
tests/client.js
267
tests/client.js
|
|
@ -15,7 +15,7 @@ chai.use(chaiAsPromised);
|
|||
|
||||
const remoteId = helper.remoteId;
|
||||
|
||||
describe('Client', function() {
|
||||
describe('Client', function () {
|
||||
describe('User Agent', function () {
|
||||
it('should set user agent on browser', async function () {
|
||||
this.timeout(25000);
|
||||
|
|
@ -28,7 +28,9 @@ describe('Client', function() {
|
|||
const browserUA = await client.pupBrowser.userAgent();
|
||||
expect(browserUA).to.equal(DefaultOptions.userAgent);
|
||||
|
||||
const pageUA = await client.pupPage.evaluate(() => window.navigator.userAgent);
|
||||
const pageUA = await client.pupPage.evaluate(
|
||||
() => window.navigator.userAgent,
|
||||
);
|
||||
expect(pageUA).to.equal(DefaultOptions.userAgent);
|
||||
|
||||
await client.destroy();
|
||||
|
|
@ -36,12 +38,15 @@ describe('Client', function() {
|
|||
|
||||
it('should set custom user agent on browser', async function () {
|
||||
this.timeout(25000);
|
||||
const customUA = DefaultOptions.userAgent.replace(/Chrome\/.* /, 'Chrome/99.9.9999.999 ');
|
||||
const customUA = DefaultOptions.userAgent.replace(
|
||||
/Chrome\/.* /,
|
||||
'Chrome/99.9.9999.999 ',
|
||||
);
|
||||
|
||||
const client = helper.createClient({
|
||||
options: {
|
||||
userAgent: customUA
|
||||
}
|
||||
userAgent: customUA,
|
||||
},
|
||||
});
|
||||
|
||||
client.initialize();
|
||||
|
|
@ -51,7 +56,9 @@ describe('Client', function() {
|
|||
expect(browserUA).to.equal(customUA);
|
||||
expect(browserUA.includes('Chrome/99.9.9999.999')).to.equal(true);
|
||||
|
||||
const pageUA = await client.pupPage.evaluate(() => window.navigator.userAgent);
|
||||
const pageUA = await client.pupPage.evaluate(
|
||||
() => window.navigator.userAgent,
|
||||
);
|
||||
expect(pageUA).to.equal(customUA);
|
||||
|
||||
await client.destroy();
|
||||
|
|
@ -60,14 +67,17 @@ describe('Client', function() {
|
|||
it('should respect an existing user agent arg', async function () {
|
||||
this.timeout(25000);
|
||||
|
||||
const customUA = DefaultOptions.userAgent.replace(/Chrome\/.* /, 'Chrome/99.9.9999.999 ');
|
||||
const customUA = DefaultOptions.userAgent.replace(
|
||||
/Chrome\/.* /,
|
||||
'Chrome/99.9.9999.999 ',
|
||||
);
|
||||
|
||||
const client = helper.createClient({
|
||||
options: {
|
||||
puppeteer: {
|
||||
args: [`--user-agent=${customUA}`]
|
||||
}
|
||||
}
|
||||
args: [`--user-agent=${customUA}`],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
client.initialize();
|
||||
|
|
@ -77,7 +87,9 @@ describe('Client', function() {
|
|||
expect(browserUA).to.equal(customUA);
|
||||
expect(browserUA.includes('Chrome/99.9.9999.999')).to.equal(true);
|
||||
|
||||
const pageUA = await client.pupPage.evaluate(() => window.navigator.userAgent);
|
||||
const pageUA = await client.pupPage.evaluate(
|
||||
() => window.navigator.userAgent,
|
||||
);
|
||||
expect(pageUA).to.equal(DefaultOptions.userAgent);
|
||||
|
||||
await client.destroy();
|
||||
|
|
@ -103,20 +115,26 @@ describe('Client', function() {
|
|||
|
||||
it('should disconnect after reaching max qr retries', async function () {
|
||||
this.timeout(50000);
|
||||
|
||||
|
||||
const qrCallback = sinon.spy();
|
||||
const disconnectedCallback = sinon.spy();
|
||||
|
||||
const client = helper.createClient({ options: { qrMaxRetries: 2 } });
|
||||
|
||||
const client = helper.createClient({
|
||||
options: { qrMaxRetries: 2 },
|
||||
});
|
||||
client.on('qr', qrCallback);
|
||||
client.on('disconnected', disconnectedCallback);
|
||||
|
||||
client.initialize();
|
||||
|
||||
await helper.sleep(45000);
|
||||
|
||||
|
||||
expect(qrCallback.calledThrice).to.eql(true);
|
||||
expect(disconnectedCallback.calledOnceWith('Max qrcode retries reached')).to.eql(true);
|
||||
expect(
|
||||
disconnectedCallback.calledOnceWith(
|
||||
'Max qrcode retries reached',
|
||||
),
|
||||
).to.eql(true);
|
||||
});
|
||||
|
||||
it('should authenticate with existing session', async function () {
|
||||
|
|
@ -137,7 +155,7 @@ describe('Client', function() {
|
|||
await client.initialize();
|
||||
|
||||
expect(authenticatedCallback.called).to.equal(true);
|
||||
|
||||
|
||||
expect(readyCallback.called).to.equal(true);
|
||||
expect(qrCallback.called).to.equal(false);
|
||||
|
||||
|
|
@ -145,12 +163,12 @@ describe('Client', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Authenticated', function() {
|
||||
describe('Authenticated', function () {
|
||||
let client;
|
||||
|
||||
before(async function() {
|
||||
before(async function () {
|
||||
this.timeout(35000);
|
||||
client = helper.createClient({authenticated: true});
|
||||
client = helper.createClient({ authenticated: true });
|
||||
await client.initialize();
|
||||
});
|
||||
|
||||
|
|
@ -164,9 +182,8 @@ describe('Client', function() {
|
|||
console.log(`WA Version: ${version}`);
|
||||
});
|
||||
|
||||
|
||||
describe('Send Messages', function () {
|
||||
it('can send a message', async function() {
|
||||
describe('Send Messages', function () {
|
||||
it('can send a message', async function () {
|
||||
const msg = await client.sendMessage(remoteId, 'hello world');
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.TEXT);
|
||||
|
|
@ -174,25 +191,29 @@ describe('Client', function() {
|
|||
expect(msg.body).to.equal('hello world');
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a media message', async function() {
|
||||
|
||||
it('can send a media message', async function () {
|
||||
const media = new MessageMedia(
|
||||
'image/png',
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3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rYU/4iuS5Z2Hdt0rvCLFdmLEXcU30AGddST62o+sLcf5l6k7CP+ru4pLYqX/VFyxbm/utQbx/r22ZEbTb2f5I2kns1Y1OQR8ZyofX+TjJxj1Rz7QQVnf1QzR26Oth0ueJVYcRP6ZUPac/Rx/5M6ixO1dhSrT3Y1DpiYmx3tF4ZUdpz9LD/dSg9PXES0LB71BwcGjKROuV28lnvnv7HHJsezheBGH5+X2CfSfRbMKW+5aGs3JFjMrjGibJc0S7TJzqjHrh2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII=',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {caption: 'here\'s my media'});
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {
|
||||
caption: "here's my media",
|
||||
});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.IMAGE);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
expect(msg.hasMedia).to.equal(true);
|
||||
expect(msg.body).to.equal('here\'s my media');
|
||||
expect(msg.body).to.equal("here's my media");
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a media message from URL', async function() {
|
||||
const media = await MessageMedia.fromUrl('https://via.placeholder.com/350x150.png');
|
||||
|
||||
it('can send a media message from URL', async function () {
|
||||
const media = await MessageMedia.fromUrl(
|
||||
'https://via.placeholder.com/350x150.png',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media);
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.IMAGE);
|
||||
|
|
@ -200,15 +221,17 @@ describe('Client', function() {
|
|||
expect(msg.hasMedia).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a media message as a document', async function() {
|
||||
|
||||
it('can send a media message as a document', async function () {
|
||||
const media = new MessageMedia(
|
||||
'image/png',
|
||||
'image/png',
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64z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5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII=',
|
||||
'this is my filename.png'
|
||||
'this is my filename.png',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, { sendMediaAsDocument: true});
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {
|
||||
sendMediaAsDocument: true,
|
||||
});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.DOCUMENT);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
|
|
@ -216,31 +239,15 @@ describe('Client', function() {
|
|||
expect(msg.body).to.equal('this is my filename.png');
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a sticker message', async function() {
|
||||
|
||||
it('can send a sticker message', async function () {
|
||||
const media = new MessageMedia(
|
||||
'image/png',
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmGYr2OWRK/ReIKI8Zt7Hb19wTcQ0uTkGh13bQupcw7gPOvdo12/5CzNtNR7xLUtNtT3CGBQ6g3InjY720pvofUec22LJPr8PhEp2OMPyI40PdwWUdronCu9yQpdPx53bQlfLKnfOVhlnDYRBXve4Ov+IZTeMgdedm0NR+xoXJeQvdJ3CvziykSukwil16W/Oe7aGjIjqc/9ib4jQlJy0uArtN4A0+cvXFvDkmUJ47sJ1Y1ATLDNVXZkNPIepQzxy1ki9fqiwbUj/I+64zxWNzyZnPuhvohJ9K70VvXBixpcu2SAHU+Xd9EKdEJDNpYP3AQr3bQSpPQ6Y6/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2hDybj9XRXNZa89Aro55XBdbW5wti2c/5WJ7jJ1RolVUn/HWpb0I58Tziup6Rx7Dm2hnbRP1GM9PW/NFmQ4PtVRVN63Wvxfmu5sowDMMwDMMwDMMwDMMwDMMwDMMwzL+CpT//F/6beoV8zb2Jmt4Qryx6lTUCsENQ75HOkhXAO3EPVgyQtKtUy3C/e+FJg17Zjnew1Xrdb9InbG4WqfUAftG+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII=',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {sendMediaAsSticker: true});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.STICKER);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
expect(msg.hasMedia).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a sticker message with custom author and name', async function() {
|
||||
const media = new MessageMedia(
|
||||
'image/png',
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZE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G+WhLwPVyfg536+MU7m4C1CMk4ZznpXZzDYI1PDL2nS1hpvc5cNd7E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII='
|
||||
);
|
||||
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {
|
||||
sendMediaAsSticker: true,
|
||||
stickerAuthor: 'WWEBJS',
|
||||
stickerName: 'My Sticker'
|
||||
sendMediaAsSticker: true,
|
||||
});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.STICKER);
|
||||
|
|
@ -248,23 +255,47 @@ describe('Client', function() {
|
|||
expect(msg.hasMedia).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a location message', async function() {
|
||||
const location = new Location(37.422, -122.084, 'Googleplex\nGoogle Headquarters');
|
||||
|
||||
|
||||
it('can send a sticker message with custom author and name', async function () {
|
||||
const media = new MessageMedia(
|
||||
'image/png',
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAV4AAACWBAMAAABkyf1EAAAAG1BMVEXMzMyWlpacnJyqqqrFxcWxsbGjo6O3t7e+vr6He3KoAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEcElEQVR4nO2aTW/bRhCGh18ij1zKknMkbbf2UXITIEeyMhIfRaF1exQLA/JRclslRykO+rs7s7s0VwytNmhJtsA8gHZEcox9PTs7uysQgGEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYhmEYh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E2sJg05Fe7/7d3Fln8Cvc3bwB616auxsKl4WPghjemHrDqyDWeu1UNW5s2btPnSQ75oOdunEwWazfwgVG0kqluYCM9OIjWOGnfA2b9G4Ha63XKpvQ8perTvTifJNhi6+WMWmi7smEZf6G8MmhlyGq+NqP8GV84TLuJr7UIQVx+bDEoEpRZIz42gs40OuN4Mv8hXzelV7KX1isH+ewTWckikyVv+CfHuqVF7I16gN0VKypX6wPsE+zFPzkinolU9UH8OMGvSpnZqKsv13p/RsMun6X5x/y2LeAr8O66lsBwzBMP/wJfyGq8pgBk6IAAAAASUVORK5CYII=',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, media, {
|
||||
sendMediaAsSticker: true,
|
||||
stickerAuthor: 'WWEBJS',
|
||||
stickerName: 'My Sticker',
|
||||
});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.STICKER);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
expect(msg.hasMedia).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
});
|
||||
|
||||
it('can send a location message', async function () {
|
||||
const location = new Location(
|
||||
37.422,
|
||||
-122.084,
|
||||
'Googleplex\nGoogle Headquarters',
|
||||
);
|
||||
|
||||
const msg = await client.sendMessage(remoteId, location);
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.LOCATION);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
|
||||
|
||||
expect(msg.location).to.be.instanceOf(Location);
|
||||
expect(msg.location.latitude).to.equal(37.422);
|
||||
expect(msg.location.longitude).to.equal(-122.084);
|
||||
expect(msg.location.description).to.equal('Googleplex\nGoogle Headquarters');
|
||||
expect(msg.location.description).to.equal(
|
||||
'Googleplex\nGoogle Headquarters',
|
||||
);
|
||||
});
|
||||
|
||||
it('can send a vCard as a contact card message', async function() {
|
||||
|
||||
it('can send a vCard as a contact card message', async function () {
|
||||
const vCard = `BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN;CHARSET=UTF-8:John Doe
|
||||
|
|
@ -273,7 +304,7 @@ EMAIL;CHARSET=UTF-8;type=HOME,INTERNET:john@doe.com
|
|||
TEL;TYPE=HOME,VOICE:1234567890
|
||||
REV:2021-06-06T02:35:53.559Z
|
||||
END:VCARD`;
|
||||
|
||||
|
||||
const msg = await client.sendMessage(remoteId, vCard);
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD);
|
||||
|
|
@ -283,8 +314,8 @@ END:VCARD`;
|
|||
expect(msg.vCards).to.have.lengthOf(1);
|
||||
expect(msg.vCards[0]).to.equal(vCard);
|
||||
});
|
||||
|
||||
it('can optionally turn off vCard parsing', async function() {
|
||||
|
||||
it('can optionally turn off vCard parsing', async function () {
|
||||
const vCard = `BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN;CHARSET=UTF-8:John Doe
|
||||
|
|
@ -293,18 +324,20 @@ EMAIL;CHARSET=UTF-8;type=HOME,INTERNET:john@doe.com
|
|||
TEL;TYPE=HOME,VOICE:1234567890
|
||||
REV:2021-06-06T02:35:53.559Z
|
||||
END:VCARD`;
|
||||
|
||||
const msg = await client.sendMessage(remoteId, vCard, {parseVCards: false});
|
||||
|
||||
const msg = await client.sendMessage(remoteId, vCard, {
|
||||
parseVCards: false,
|
||||
});
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.TEXT); // not a contact card
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
expect(msg.to).to.equal(remoteId);
|
||||
expect(msg.body).to.equal(vCard);
|
||||
});
|
||||
|
||||
it('can send a Contact as a contact card message', async function() {
|
||||
|
||||
it('can send a Contact as a contact card message', async function () {
|
||||
const contact = await client.getContactById(remoteId);
|
||||
|
||||
|
||||
const msg = await client.sendMessage(remoteId, contact);
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD);
|
||||
|
|
@ -314,12 +347,16 @@ END:VCARD`;
|
|||
expect(msg.vCards).to.have.lengthOf(1);
|
||||
expect(msg.vCards[0]).to.match(/BEGIN:VCARD/);
|
||||
});
|
||||
|
||||
|
||||
it('can send multiple Contacts as a contact card message', async function () {
|
||||
const contact1 = await client.getContactById(remoteId);
|
||||
const contact2 = await client.getContactById('5511942167462@c.us'); //iFood
|
||||
|
||||
const msg = await client.sendMessage(remoteId, [contact1, contact2]);
|
||||
const contact2 =
|
||||
await client.getContactById('5511942167462@c.us'); //iFood
|
||||
|
||||
const msg = await client.sendMessage(remoteId, [
|
||||
contact1,
|
||||
contact2,
|
||||
]);
|
||||
expect(msg).to.be.instanceOf(Message);
|
||||
expect(msg.type).to.equal(MessageTypes.CONTACT_CARD_MULTI);
|
||||
expect(msg.fromMe).to.equal(true);
|
||||
|
|
@ -329,38 +366,40 @@ END:VCARD`;
|
|||
expect(msg.vCards[1]).to.match(/BEGIN:VCARD/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Get Chats', function () {
|
||||
|
||||
describe('Get Chats', function () {
|
||||
it('can get a chat by its ID', async function () {
|
||||
const chat = await client.getChatById(remoteId);
|
||||
expect(chat).to.be.instanceOf(Chat);
|
||||
expect(chat.id._serialized).to.eql(remoteId);
|
||||
expect(chat.isGroup).to.eql(false);
|
||||
});
|
||||
|
||||
|
||||
it('can get all chats', async function () {
|
||||
const chats = await client.getChats();
|
||||
expect(chats.length).to.be.greaterThanOrEqual(1);
|
||||
|
||||
const chat = chats.find(c => c.id._serialized === remoteId);
|
||||
|
||||
const chat = chats.find((c) => c.id._serialized === remoteId);
|
||||
expect(chat).to.exist;
|
||||
expect(chat).to.be.instanceOf(Chat);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Get Contacts', function () {
|
||||
describe('Get Contacts', function () {
|
||||
it('can get a contact by its ID', async function () {
|
||||
const contact = await client.getContactById(remoteId);
|
||||
expect(contact).to.be.instanceOf(Contact);
|
||||
expect(contact.id._serialized).to.eql(remoteId);
|
||||
expect(contact.number).to.eql(remoteId.split('@')[0]);
|
||||
});
|
||||
|
||||
|
||||
it('can get all contacts', async function () {
|
||||
const contacts = await client.getContacts();
|
||||
expect(contacts.length).to.be.greaterThanOrEqual(1);
|
||||
|
||||
const contact = contacts.find(c => c.id._serialized === remoteId);
|
||||
|
||||
const contact = contacts.find(
|
||||
(c) => c.id._serialized === remoteId,
|
||||
);
|
||||
expect(contact).to.exist;
|
||||
expect(contact).to.be.instanceOf(Contact);
|
||||
});
|
||||
|
|
@ -377,10 +416,11 @@ END:VCARD`;
|
|||
const blockedContacts = await client.getBlockedContacts();
|
||||
expect(blockedContacts.length).to.be.greaterThanOrEqual(1);
|
||||
|
||||
const contact = blockedContacts.find(c => c.id._serialized === remoteId);
|
||||
const contact = blockedContacts.find(
|
||||
(c) => c.id._serialized === remoteId,
|
||||
);
|
||||
expect(contact).to.exist;
|
||||
expect(contact).to.be.instanceOf(Contact);
|
||||
|
||||
});
|
||||
|
||||
it('can unblock a contact', async function () {
|
||||
|
|
@ -399,27 +439,28 @@ END:VCARD`;
|
|||
});
|
||||
|
||||
it('can verify that a user is not registered', async function () {
|
||||
const isRegistered = await client.isRegisteredUser('9999999999@c.us');
|
||||
const isRegistered =
|
||||
await client.isRegisteredUser('9999999999@c.us');
|
||||
expect(isRegistered).to.be.false;
|
||||
});
|
||||
|
||||
it('can get a number\'s whatsapp id', async function () {
|
||||
it("can get a number's whatsapp id", async function () {
|
||||
const number = remoteId.split('@')[0];
|
||||
const numberId = await client.getNumberId(number);
|
||||
expect(numberId).to.eql({
|
||||
server: 'c.us',
|
||||
user: number,
|
||||
_serialized: `${number}@c.us`
|
||||
_serialized: `${number}@c.us`,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns null when getting an unregistered number\'s whatsapp id', async function () {
|
||||
it("returns null when getting an unregistered number's whatsapp id", async function () {
|
||||
const number = '9999999999';
|
||||
const numberId = await client.getNumberId(number);
|
||||
expect(numberId).to.eql(null);
|
||||
});
|
||||
|
||||
it('can get a number\'s country code', async function () {
|
||||
it("can get a number's country code", async function () {
|
||||
const number = '18092201111';
|
||||
const countryCode = await client.getCountryCode(number);
|
||||
expect(countryCode).to.eql('1');
|
||||
|
|
@ -440,18 +481,30 @@ END:VCARD`;
|
|||
|
||||
describe('Search messages', function () {
|
||||
it('can search for messages', async function () {
|
||||
const m1 = await client.sendMessage(remoteId, 'I\'m searching for Super Mario Brothers');
|
||||
const m2 = await client.sendMessage(remoteId, 'This also contains Mario');
|
||||
const m3 = await client.sendMessage(remoteId, 'Nothing of interest here, just Luigi');
|
||||
|
||||
const m1 = await client.sendMessage(
|
||||
remoteId,
|
||||
"I'm searching for Super Mario Brothers",
|
||||
);
|
||||
const m2 = await client.sendMessage(
|
||||
remoteId,
|
||||
'This also contains Mario',
|
||||
);
|
||||
const m3 = await client.sendMessage(
|
||||
remoteId,
|
||||
'Nothing of interest here, just Luigi',
|
||||
);
|
||||
|
||||
// wait for search index to catch up
|
||||
await helper.sleep(1000);
|
||||
|
||||
const msgs = await client.searchMessages('Mario', {chatId: remoteId});
|
||||
|
||||
const msgs = await client.searchMessages('Mario', {
|
||||
chatId: remoteId,
|
||||
});
|
||||
expect(msgs.length).to.be.greaterThanOrEqual(2);
|
||||
const msgIds = msgs.map(m => m.id._serialized);
|
||||
const msgIds = msgs.map((m) => m.id._serialized);
|
||||
expect(msgIds).to.include.members([
|
||||
m1.id._serialized, m2.id._serialized
|
||||
m1.id._serialized,
|
||||
m2.id._serialized,
|
||||
]);
|
||||
expect(msgIds).to.not.include.members([m3.id._serialized]);
|
||||
});
|
||||
|
|
@ -468,7 +521,7 @@ END:VCARD`;
|
|||
after(async function () {
|
||||
await client.setStatus(previousStatus);
|
||||
});
|
||||
|
||||
|
||||
it('can set the status text', async function () {
|
||||
await client.setStatus('My shiny new status');
|
||||
|
||||
|
|
@ -478,7 +531,7 @@ END:VCARD`;
|
|||
|
||||
it('can set the status text to something else', async function () {
|
||||
await client.setStatus('Busy');
|
||||
|
||||
|
||||
const status = await me.getAbout();
|
||||
expect(status).to.eql('Busy');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,30 +3,32 @@ const { Client, LocalAuth } = require('..');
|
|||
require('dotenv').config();
|
||||
|
||||
const remoteId = process.env.WWEBJS_TEST_REMOTE_ID;
|
||||
if(!remoteId) throw new Error('The WWEBJS_TEST_REMOTE_ID environment variable has not been set.');
|
||||
if (!remoteId)
|
||||
throw new Error(
|
||||
'The WWEBJS_TEST_REMOTE_ID environment variable has not been set.',
|
||||
);
|
||||
|
||||
|
||||
function createClient({authenticated, options: additionalOpts}={}) {
|
||||
function createClient({ authenticated, options: additionalOpts } = {}) {
|
||||
const options = {};
|
||||
|
||||
if(authenticated) {
|
||||
if (authenticated) {
|
||||
const clientId = process.env.WWEBJS_TEST_CLIENT_ID;
|
||||
if(!clientId) throw new Error('No session found in environment.');
|
||||
if (!clientId) throw new Error('No session found in environment.');
|
||||
options.authStrategy = new LocalAuth({
|
||||
clientId
|
||||
clientId,
|
||||
});
|
||||
}
|
||||
|
||||
const allOpts = {...options, ...(additionalOpts || {})};
|
||||
const allOpts = { ...options, ...(additionalOpts || {}) };
|
||||
return new Client(allOpts);
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sleep,
|
||||
sleep,
|
||||
createClient,
|
||||
remoteId,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ describe('Chat', function () {
|
|||
let client;
|
||||
let chat;
|
||||
|
||||
before(async function() {
|
||||
before(async function () {
|
||||
this.timeout(35000);
|
||||
client = helper.createClient({ authenticated: true });
|
||||
await client.initialize();
|
||||
|
|
@ -39,7 +39,7 @@ describe('Chat', function () {
|
|||
const messages = await chat.fetchMessages();
|
||||
expect(messages.length).to.be.greaterThanOrEqual(2);
|
||||
|
||||
const fetchedMsg = messages[messages.length-1];
|
||||
const fetchedMsg = messages[messages.length - 1];
|
||||
expect(fetchedMsg).to.be.instanceOf(Message);
|
||||
expect(fetchedMsg.type).to.equal(MessageTypes.TEXT);
|
||||
expect(fetchedMsg.id._serialized).to.equal(msg.id._serialized);
|
||||
|
|
@ -47,11 +47,11 @@ describe('Chat', function () {
|
|||
});
|
||||
|
||||
it('can use a limit when fetching messages sent in a chat', async function () {
|
||||
await helper.sleep(1000);
|
||||
await helper.sleep(1000);
|
||||
const msg = await chat.sendMessage('yet another message');
|
||||
await helper.sleep(500);
|
||||
|
||||
const messages = await chat.fetchMessages({limit: 1});
|
||||
const messages = await chat.fetchMessages({ limit: 1 });
|
||||
expect(messages).to.have.lengthOf(1);
|
||||
|
||||
const fetchedMsg = messages[0];
|
||||
|
|
@ -62,12 +62,12 @@ describe('Chat', function () {
|
|||
});
|
||||
|
||||
it('can use fromMe=true when fetching messages sent in a chat to get only bot messages', async function () {
|
||||
const messages = await chat.fetchMessages({fromMe: true});
|
||||
const messages = await chat.fetchMessages({ fromMe: true });
|
||||
expect(messages).to.have.lengthOf(2);
|
||||
});
|
||||
|
||||
it('can use fromMe=false when fetching messages sent in a chat to get only non bot messages', async function () {
|
||||
const messages = await chat.fetchMessages({fromMe: false});
|
||||
const messages = await chat.fetchMessages({ fromMe: false });
|
||||
expect(messages).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ describe('Chat', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Archiving', function (){
|
||||
describe('Archiving', function () {
|
||||
it('can archive a chat', async function () {
|
||||
const res = await chat.archive();
|
||||
expect(res).to.equal(true);
|
||||
|
|
@ -147,7 +147,7 @@ describe('Chat', function () {
|
|||
});
|
||||
|
||||
describe('Muting', function () {
|
||||
it('can mute a chat forever', async function() {
|
||||
it('can mute a chat forever', async function () {
|
||||
await chat.mute();
|
||||
|
||||
await helper.sleep(1000);
|
||||
|
|
@ -158,8 +158,8 @@ describe('Chat', function () {
|
|||
expect(chat.muteExpiration).to.equal(-1);
|
||||
});
|
||||
|
||||
it('can mute a chat until a specific date', async function() {
|
||||
const unmuteDate = new Date(new Date().getTime() + (1000*60*60));
|
||||
it('can mute a chat until a specific date', async function () {
|
||||
const unmuteDate = new Date(new Date().getTime() + 1000 * 60 * 60);
|
||||
await chat.mute(unmuteDate);
|
||||
|
||||
await helper.sleep(1000);
|
||||
|
|
@ -168,36 +168,36 @@ describe('Chat', function () {
|
|||
chat = await client.getChatById(remoteId);
|
||||
expect(chat.isMuted).to.equal(true);
|
||||
expect(chat.muteExpiration).to.equal(
|
||||
Math.round(unmuteDate.getTime() / 1000)
|
||||
Math.round(unmuteDate.getTime() / 1000),
|
||||
);
|
||||
});
|
||||
|
||||
it('can unmute a chat', async function () {
|
||||
await chat.unmute();
|
||||
await helper.sleep(500);
|
||||
|
||||
|
||||
// refresh chat
|
||||
chat = await client.getChatById(remoteId);
|
||||
expect(chat.isMuted).to.equal(false);
|
||||
expect(chat.muteExpiration).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// eslint-disable-next-line mocha/no-skipped-tests
|
||||
describe.skip('Destructive operations', function () {
|
||||
it('can clear all messages from chat', async function () {
|
||||
it('can clear all messages from chat', async function () {
|
||||
const res = await chat.clearMessages();
|
||||
expect(res).to.equal(true);
|
||||
|
||||
|
||||
await helper.sleep(3000);
|
||||
|
||||
|
||||
const msgs = await chat.fetchMessages();
|
||||
expect(msgs).to.have.lengthOf(0);
|
||||
});
|
||||
|
||||
|
||||
it('can delete a chat', async function () {
|
||||
const res = await chat.delete();
|
||||
expect(res).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,18 +3,20 @@ const helper = require('../helper');
|
|||
|
||||
const remoteId = helper.remoteId;
|
||||
|
||||
describe('Group', function() {
|
||||
describe('Group', function () {
|
||||
let client;
|
||||
let group;
|
||||
|
||||
before(async function() {
|
||||
before(async function () {
|
||||
this.timeout(35000);
|
||||
client = helper.createClient({
|
||||
authenticated: true,
|
||||
authenticated: true,
|
||||
});
|
||||
await client.initialize();
|
||||
|
||||
const createRes = await client.createGroup('My Awesome Group', [remoteId]);
|
||||
const createRes = await client.createGroup('My Awesome Group', [
|
||||
remoteId,
|
||||
]);
|
||||
expect(createRes.gid).to.exist;
|
||||
await helper.sleep(500);
|
||||
group = await client.getChatById(createRes.gid._serialized);
|
||||
|
|
@ -34,7 +36,7 @@ describe('Group', function() {
|
|||
await helper.sleep(1000);
|
||||
|
||||
// reload
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
expect(group.name).to.equal('My Amazing Group');
|
||||
});
|
||||
|
||||
|
|
@ -47,7 +49,7 @@ describe('Group', function() {
|
|||
await helper.sleep(1000);
|
||||
|
||||
// reload
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
expect(group.description).to.equal('some description');
|
||||
});
|
||||
|
||||
|
|
@ -127,7 +129,9 @@ describe('Group', function() {
|
|||
|
||||
describe('Participants', function () {
|
||||
it('can promote a user to admin', async function () {
|
||||
let participant = group.participants.find(p => p.id._serialized === remoteId);
|
||||
let participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
expect(participant.isAdmin).to.equal(false);
|
||||
|
||||
|
|
@ -138,13 +142,17 @@ describe('Group', function() {
|
|||
|
||||
// reload and check
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
expect(participant.isAdmin).to.equal(true);
|
||||
});
|
||||
|
||||
it('can demote a user', async function () {
|
||||
let participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
let participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
expect(participant.isAdmin).to.equal(true);
|
||||
|
||||
|
|
@ -155,13 +163,17 @@ describe('Group', function() {
|
|||
|
||||
// reload and check
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
expect(participant.isAdmin).to.equal(false);
|
||||
});
|
||||
|
||||
it('can remove a user from the group', async function () {
|
||||
let participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
let participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
|
||||
const res = await group.removeParticipants([remoteId]);
|
||||
|
|
@ -171,12 +183,16 @@ describe('Group', function() {
|
|||
|
||||
// reload and check
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.not.exist;
|
||||
});
|
||||
|
||||
it('can add back a user to the group', async function () {
|
||||
let participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
let participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.not.exist;
|
||||
|
||||
const res = await group.addParticipants([remoteId]);
|
||||
|
|
@ -186,14 +202,16 @@ describe('Group', function() {
|
|||
|
||||
// reload and check
|
||||
group = await client.getChatById(group.id._serialized);
|
||||
participant = group.participants.find(p => p.id._serialized=== remoteId);
|
||||
participant = group.participants.find(
|
||||
(p) => p.id._serialized === remoteId,
|
||||
);
|
||||
expect(participant).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
describe('Leave / re-join', function () {
|
||||
let code;
|
||||
|
||||
|
||||
before(async function () {
|
||||
code = await group.getInviteCode();
|
||||
});
|
||||
|
|
@ -224,5 +242,4 @@ describe('Group', function() {
|
|||
after(async function () {
|
||||
await client.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ describe('Message', function () {
|
|||
let chat;
|
||||
let message;
|
||||
|
||||
before(async function() {
|
||||
before(async function () {
|
||||
this.timeout(35000);
|
||||
client = helper.createClient({ authenticated: true });
|
||||
await client.initialize();
|
||||
|
|
@ -88,7 +88,7 @@ describe('Message', function () {
|
|||
describe('Delete', function () {
|
||||
it('can delete a message for me', async function () {
|
||||
await message.delete();
|
||||
|
||||
|
||||
await helper.sleep(5000);
|
||||
expect(await message.reload()).to.equal(null);
|
||||
});
|
||||
|
|
@ -105,12 +105,14 @@ describe('Message', function () {
|
|||
|
||||
expect(await message.reload()).to.equal(null);
|
||||
expect(callback.called).to.equal(true);
|
||||
const [ revokeMsg, originalMsg ] = callback.args[0];
|
||||
expect(revokeMsg.id._serialized).to.equal(originalMsg.id._serialized);
|
||||
const [revokeMsg, originalMsg] = callback.args[0];
|
||||
expect(revokeMsg.id._serialized).to.equal(
|
||||
originalMsg.id._serialized,
|
||||
);
|
||||
expect(originalMsg.body).to.equal('sneaky message');
|
||||
expect(originalMsg.type).to.equal('chat');
|
||||
expect(revokeMsg.body).to.equal('');
|
||||
expect(revokeMsg.type).to.equal('revoked');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue