Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
matrix-appservice-discord
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
salixor
matrix-appservice-discord
Validations
b88c1523
Non vérifiée
Valider
b88c1523
rédigé
22 déc. 2018
par
Sorunome
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
accidentally add tests
parent
28eccc02
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
test/mocks/message.ts
+2
-0
2 ajouts, 0 suppression
test/mocks/message.ts
test/test_discordbot.ts
+172
-3
172 ajouts, 3 suppressions
test/test_discordbot.ts
avec
174 ajouts
et
3 suppressions
test/mocks/message.ts
+
2
−
0
Voir le fichier @
b88c1523
import
*
as
Discord
from
"
discord.js
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
{
MockUser
}
from
"
./user
"
;
import
{
MockUser
}
from
"
./user
"
;
import
{
MockCollection
}
from
"
./collection
"
;
// we are a test file and thus need those
// we are a test file and thus need those
/* tslint:disable:no-unused-expression max-file-line-count no-any */
/* tslint:disable:no-unused-expression max-file-line-count no-any */
export
class
MockMessage
{
export
class
MockMessage
{
public
attachments
=
new
MockCollection
<
string
,
any
>
();
public
embeds
:
any
[]
=
[];
public
embeds
:
any
[]
=
[];
public
content
=
""
;
public
content
=
""
;
public
channel
:
Discord
.
TextChannel
|
undefined
;
public
channel
:
Discord
.
TextChannel
|
undefined
;
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_discordbot.ts
+
172
−
3
Voir le fichier @
b88c1523
...
@@ -8,6 +8,7 @@ import { MockMember } from "./mocks/member";
...
@@ -8,6 +8,7 @@ import { MockMember } from "./mocks/member";
import
{
DiscordBot
}
from
"
../src/bot
"
;
import
{
DiscordBot
}
from
"
../src/bot
"
;
import
{
MockDiscordClient
}
from
"
./mocks/discordclient
"
;
import
{
MockDiscordClient
}
from
"
./mocks/discordclient
"
;
import
{
MockMessage
}
from
"
./mocks/message
"
;
import
{
MockMessage
}
from
"
./mocks/message
"
;
import
{
Util
}
from
"
../src/util
"
;
// we are a test file and thus need those
// we are a test file and thus need those
/* tslint:disable:no-unused-expression max-file-line-count no-any */
/* tslint:disable:no-unused-expression max-file-line-count no-any */
...
@@ -46,6 +47,14 @@ const mockBridge = {
...
@@ -46,6 +47,14 @@ const mockBridge = {
const
modDiscordBot
=
Proxyquire
(
"
../src/bot
"
,
{
const
modDiscordBot
=
Proxyquire
(
"
../src/bot
"
,
{
"
./clientfactory
"
:
require
(
"
./mocks/discordclientfactory
"
),
"
./clientfactory
"
:
require
(
"
./mocks/discordclientfactory
"
),
"
./util
"
:
{
Util
:
{
AsyncForEach
:
Util
.
AsyncForEach
,
UploadContentFromUrl
:
async
()
=>
{
return
{
mxcUrl
:
"
uploaded
"
};
},
},
},
});
});
describe
(
"
DiscordBot
"
,
()
=>
{
describe
(
"
DiscordBot
"
,
()
=>
{
let
discordBot
;
let
discordBot
;
...
@@ -103,6 +112,169 @@ describe("DiscordBot", () => {
...
@@ -103,6 +112,169 @@ describe("DiscordBot", () => {
await
discordBot
.
LookupRoom
(
"
123
"
,
"
321
"
);
await
discordBot
.
LookupRoom
(
"
123
"
,
"
321
"
);
});
});
});
});
describe
(
"
OnMessage()
"
,
()
=>
{
let
SENT_MESSAGE
=
false
;
let
MARKED
=
-
1
;
let
HANDLE_COMMAND
=
false
;
let
ATTACHMENT
=
{}
as
any
;
let
MSGTYPE
=
""
;
function
getDiscordBot
()
{
SENT_MESSAGE
=
false
;
MARKED
=
-
1
;
HANDLE_COMMAND
=
false
;
ATTACHMENT
=
{};
MSGTYPE
=
""
;
const
discord
=
new
modDiscordBot
.
DiscordBot
(
config
,
mockBridge
,
);
discord
.
bot
=
{
user
:
{
id
:
"
654
"
}
};
discord
.
provisioner
=
{
HasPendingRequest
:
(
chan
)
=>
true
,
MarkApproved
:
async
(
chan
,
member
,
approved
)
=>
{
MARKED
=
approved
?
1
:
0
;
return
approved
;
},
};
discord
.
GetIntentFromDiscordMember
=
(
_
)
=>
{
return
{
sendMessage
:
async
(
room
,
msg
)
=>
{
SENT_MESSAGE
=
true
;
if
(
msg
.
info
)
{
ATTACHMENT
=
msg
.
info
;
}
MSGTYPE
=
msg
.
msgtype
;
return
{
event_id
:
"
$fox:localhost
"
,
};
},
};
};
discord
.
userSync
=
{
OnUpdateUser
:
async
(
user
)
=>
{
},
};
discord
.
channelSync
=
{
GetRoomIdsFromChannel
:
async
(
chan
)
=>
[
"
!asdf:localhost
"
],
};
discord
.
roomHandler
=
{
HandleDiscordCommand
:
async
(
msg
)
=>
{
HANDLE_COMMAND
=
true
;
},
};
discord
.
store
=
{
Insert
:
async
(
_
)
=>
{
},
};
return
discord
;
}
it
(
"
ignores own messages
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
guild
:
any
=
new
MockGuild
(
"
123
"
,
[]);
const
author
=
new
MockMember
(
"
654
"
,
"
TestUsername
"
);
guild
.
_mockAddMember
(
author
);
const
channel
=
new
Discord
.
TextChannel
(
guild
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
author
=
author
;
msg
.
content
=
"
Hi!
"
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
SENT_MESSAGE
,
false
);
});
it
(
"
accepts !approve
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
content
=
"
!approve
"
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MARKED
,
1
);
});
it
(
"
denies !deny
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
content
=
"
!deny
"
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MARKED
,
0
);
});
it
(
"
Passes on !matrix commands
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
content
=
"
!matrix test
"
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
HANDLE_COMMAND
,
true
);
});
it
(
"
skips empty messages
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
content
=
""
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
SENT_MESSAGE
,
false
);
});
it
(
"
sends normal messages
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
content
=
"
Foxies are amazing!
"
;
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
SENT_MESSAGE
,
true
);
});
it
(
"
uploads images
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
attachments
.
set
(
"
1234
"
,
{
filename
:
"
someimage.png
"
,
filesize
:
42
,
height
:
0
,
url
:
"
asdf
"
,
width
:
0
,
});
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MSGTYPE
,
"
m.image
"
);
Chai
.
assert
.
equal
(
ATTACHMENT
.
mimetype
,
"
image/png
"
);
});
it
(
"
uploads videos
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
attachments
.
set
(
"
1234
"
,
{
filename
:
"
foxes.mov
"
,
filesize
:
42
,
height
:
0
,
url
:
"
asdf
"
,
width
:
0
,
});
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MSGTYPE
,
"
m.video
"
);
Chai
.
assert
.
equal
(
ATTACHMENT
.
mimetype
,
"
video/quicktime
"
);
});
it
(
"
uploads audio
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
attachments
.
set
(
"
1234
"
,
{
filename
:
"
meow.mp3
"
,
filesize
:
42
,
height
:
0
,
url
:
"
asdf
"
,
width
:
0
,
});
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MSGTYPE
,
"
m.audio
"
);
Chai
.
assert
.
equal
(
ATTACHMENT
.
mimetype
,
"
audio/mpeg
"
);
});
it
(
"
uploads other files
"
,
async
()
=>
{
discordBot
=
getDiscordBot
();
const
channel
=
new
Discord
.
TextChannel
({}
as
any
,
{}
as
any
);
const
msg
=
new
MockMessage
(
channel
)
as
any
;
msg
.
attachments
.
set
(
"
1234
"
,
{
filename
:
"
meow.zip
"
,
filesize
:
42
,
height
:
0
,
url
:
"
asdf
"
,
width
:
0
,
});
await
discordBot
.
OnMessage
(
msg
);
Chai
.
assert
.
equal
(
MSGTYPE
,
"
m.file
"
);
Chai
.
assert
.
equal
(
ATTACHMENT
.
mimetype
,
"
application/zip
"
);
});
});
describe
(
"
OnMessageUpdate()
"
,
()
=>
{
describe
(
"
OnMessageUpdate()
"
,
()
=>
{
it
(
"
should return on an unchanged message
"
,
async
()
=>
{
it
(
"
should return on an unchanged message
"
,
async
()
=>
{
discordBot
=
new
modDiscordBot
.
DiscordBot
(
discordBot
=
new
modDiscordBot
.
DiscordBot
(
...
@@ -232,7 +404,4 @@ describe("DiscordBot", () => {
...
@@ -232,7 +404,4 @@ describe("DiscordBot", () => {
// return assert.isFulfilled(discordBot.OnTyping( {id: "321"}, {id: "12345"}, true));
// return assert.isFulfilled(discordBot.OnTyping( {id: "321"}, {id: "12345"}, true));
// });
// });
// });
// });
// describe("OnMessage()", () => {
//
// });
});
});
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter