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
7db1ea66
Valider
7db1ea66
rédigé
Il y a 6 ans
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add essential tests for provisoner
parent
36cecf6c
Branches
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
src/provisioner.ts
+4
-4
4 ajouts, 4 suppressions
src/provisioner.ts
test/mocks/channel.ts
+6
-0
6 ajouts, 0 suppression
test/mocks/channel.ts
test/test_provisioner.ts
+81
-0
81 ajouts, 0 suppression
test/test_provisioner.ts
avec
91 ajouts
et
4 suppressions
src/provisioner.ts
+
4
−
4
Voir le fichier @
7db1ea66
...
@@ -40,7 +40,7 @@ export class Provisioner {
...
@@ -40,7 +40,7 @@ export class Provisioner {
let
responded
=
false
;
let
responded
=
false
;
let
resolve
:
(
msg
:
string
)
=>
void
;
let
resolve
:
(
msg
:
string
)
=>
void
;
let
reject
:
(
err
:
string
)
=>
void
;
let
reject
:
(
err
:
Error
)
=>
void
;
const
deferP
:
Promise
<
string
>
=
new
Promise
((
res
,
rej
)
=>
{
resolve
=
res
;
reject
=
rej
;
});
const
deferP
:
Promise
<
string
>
=
new
Promise
((
res
,
rej
)
=>
{
resolve
=
res
;
reject
=
rej
;
});
const
approveFn
=
(
approved
:
boolean
,
expired
=
false
)
=>
{
const
approveFn
=
(
approved
:
boolean
,
expired
=
false
)
=>
{
...
@@ -54,9 +54,9 @@ export class Provisioner {
...
@@ -54,9 +54,9 @@ export class Provisioner {
resolve
(
"
Approved
"
);
resolve
(
"
Approved
"
);
}
else
{
}
else
{
if
(
expired
)
{
if
(
expired
)
{
reject
(
"
Timed out waiting for a response from the Discord owners
"
);
reject
(
Error
(
"
Timed out waiting for a response from the Discord owners
"
)
)
;
}
else
{
}
else
{
reject
(
"
The bridge has been declined by the Discord guild
"
);
reject
(
Error
(
"
The bridge has been declined by the Discord guild
"
)
)
;
}
}
}
}
};
};
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
test/mocks/channel.ts
+
6
−
0
Voir le fichier @
7db1ea66
import
{
MockMember
}
from
"
./member
"
;
import
{
MockMember
}
from
"
./member
"
;
import
{
MockCollection
}
from
"
./collection
"
;
import
{
MockCollection
}
from
"
./collection
"
;
import
{
Permissions
,
PermissionResolvable
}
from
"
discord.js
"
;
// 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 */
...
@@ -14,7 +15,12 @@ export class MockChannel {
...
@@ -14,7 +15,12 @@ export class MockChannel {
public
name
:
string
=
""
,
public
name
:
string
=
""
,
public
topic
:
string
=
""
,
public
topic
:
string
=
""
,
)
{
}
)
{
}
public
async
send
(
data
:
any
):
Promise
<
any
>
{
public
async
send
(
data
:
any
):
Promise
<
any
>
{
return
data
;
return
data
;
}
}
public
permissionsFor
(
member
:
MockMember
)
{
return
new
Permissions
(
Permissions
.
FLAGS
.
MANAGE_WEBHOOKS
as
PermissionResolvable
);
}
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
test/test_provisioner.ts
0 → 100644
+
81
−
0
Voir le fichier @
7db1ea66
import
*
as
Chai
from
"
chai
"
;
import
*
as
Discord
from
"
discord.js
"
;
import
*
as
Proxyquire
from
"
proxyquire
"
;
import
{
Provisioner
}
from
"
../src/provisioner
"
;
import
{
MockChannel
}
from
"
./mocks/channel
"
;
import
{
MockMember
}
from
"
./mocks/member
"
;
// we are a test file and thus need those
/* tslint:disable:no-any */
const
expect
=
Chai
.
expect
;
const
INTERVAL
=
250
;
let
lastStatus
=
null
;
// const assert = Chai.assert;
const
bot
=
{
GetBotId
:
()
=>
{
return
"
1234
"
;
},
GetIntentFromDiscordMember
:
(
member
)
=>
{
return
{
getClient
:
()
=>
{
return
{
setPresence
:
async
(
status
)
=>
{
lastStatus
=
status
;
},
};
},
};
},
};
const
TIMEOUT_MS
=
1000
;
describe
(
"
Provisioner
"
,
()
=>
{
describe
(
"
AskBridgePermission
"
,
()
=>
{
it
(
"
should fail to bridge a room that timed out
"
,
async
()
=>
{
const
p
=
new
Provisioner
();
const
startAt
=
Date
.
now
();
await
p
.
AskBridgePermission
(
new
MockChannel
(
"
foo
"
,
"
bar
"
)
as
any
,
"
Mark
"
,
TIMEOUT_MS
,
).
then
(()
=>
{
throw
Error
(
"
Should have thrown an error
"
);
}).
catch
((
err
)
=>
{
expect
(
err
.
message
).
to
.
eq
(
"
Timed out waiting for a response from the Discord owners
"
);
const
delay
=
Date
.
now
()
-
startAt
;
if
(
delay
<
TIMEOUT_MS
)
{
throw
Error
(
`Should have waited for timeout before resolving, waited:
${
delay
}
ms`
);
}
});
});
it
(
"
should fail to bridge a room that was declined
"
,
async
()
=>
{
const
p
=
new
Provisioner
();
const
promise
=
p
.
AskBridgePermission
(
new
MockChannel
(
"
foo
"
,
"
bar
"
)
as
any
,
"
Mark
"
,
TIMEOUT_MS
,
).
then
(()
=>
{
throw
Error
(
"
Should have thrown an error
"
);
}).
catch
((
err
)
=>
{
expect
(
err
.
message
).
to
.
eq
(
"
The bridge has been declined by the Discord guild
"
);
});
await
p
.
MarkApproved
(
new
MockChannel
(
"
foo
"
,
"
bar
"
)
as
any
,
new
MockMember
(
"
abc
"
,
"
Mark
"
)
as
any
,
false
);
await
promise
;
});
it
(
"
should bridge a room that was approved
"
,
async
()
=>
{
const
p
=
new
Provisioner
();
const
promise
=
p
.
AskBridgePermission
(
new
MockChannel
(
"
foo
"
,
"
bar
"
)
as
any
,
"
Mark
"
,
TIMEOUT_MS
,
).
then
((
msg
)
=>
{
expect
(
msg
).
to
.
eq
(
"
Approved
"
);
});
await
p
.
MarkApproved
(
new
MockChannel
(
"
foo
"
,
"
bar
"
)
as
any
,
new
MockMember
(
"
abc
"
,
"
Mark
"
)
as
any
,
true
);
await
promise
;
});
});
});
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