Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
cadcc6ca
Commit
cadcc6ca
authored
10 years ago
by
Kegan Dougal
Browse files
Options
Downloads
Patches
Plain Diff
Add commands-service unit tests.
parent
11da8d0d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
syweb/webclient/test/unit/commands-service.spec.js
+143
-0
143 additions, 0 deletions
syweb/webclient/test/unit/commands-service.spec.js
with
143 additions
and
0 deletions
syweb/webclient/test/unit/commands-service.spec.js
0 → 100644
+
143
−
0
View file @
cadcc6ca
describe
(
'
CommandsService
'
,
function
()
{
var
scope
;
var
roomId
=
"
!dlwifhweu:localhost
"
;
var
testPowerLevelsEvent
,
testMatrixServicePromise
;
var
matrixService
=
{
// these will be spyed on by jasmine, hence stub methods
setDisplayName
:
function
(
args
){},
kick
:
function
(
args
){},
ban
:
function
(
args
){},
unban
:
function
(
args
){},
setUserPowerLevel
:
function
(
args
){}
};
var
modelService
=
{
getRoom
:
function
(
roomId
)
{
return
{
room_id
:
roomId
,
current_room_state
:
{
events
:
{
"
m.room.power_levels
"
:
testPowerLevelsEvent
},
state
:
function
(
type
,
key
)
{
return
key
?
this
.
events
[
type
+
key
]
:
this
.
events
[
type
];
}
}
};
}
};
// helper function for asserting promise outcomes
NOTHING
=
"
[Promise]
"
;
RESOLVED
=
"
[Resolved promise]
"
;
REJECTED
=
"
[Rejected promise]
"
;
var
expectPromise
=
function
(
promise
,
expects
)
{
var
value
=
NOTHING
;
promise
.
then
(
function
(
result
)
{
value
=
RESOLVED
;
},
function
(
fail
)
{
value
=
REJECTED
;
});
scope
.
$apply
();
expect
(
value
).
toEqual
(
expects
);
};
// setup the service and mocked dependencies
beforeEach
(
function
()
{
// set default mock values
testPowerLevelsEvent
=
{
content
:
{
default
:
50
},
user_id
:
"
@foo:bar
"
,
room_id
:
roomId
}
// mocked dependencies
module
(
function
(
$provide
)
{
$provide
.
value
(
'
matrixService
'
,
matrixService
);
$provide
.
value
(
'
modelService
'
,
modelService
);
});
// tested service
module
(
'
commandsService
'
);
});
beforeEach
(
inject
(
function
(
$rootScope
,
$q
)
{
scope
=
$rootScope
;
testMatrixServicePromise
=
$q
.
defer
();
}));
it
(
'
should reject a no-arg "/nick".
'
,
inject
(
function
(
commandsService
)
{
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/nick
"
);
expectPromise
(
promise
,
REJECTED
);
}));
it
(
'
should be able to set a /nick with multiple words.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
setDisplayName
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/nick Bob Smith
"
);
expect
(
matrixService
.
setDisplayName
).
toHaveBeenCalledWith
(
"
Bob Smith
"
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /kick a user without a reason.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
kick
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/kick @bob:matrix.org
"
);
expect
(
matrixService
.
kick
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
undefined
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /kick a user with a reason.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
kick
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/kick @bob:matrix.org he smells
"
);
expect
(
matrixService
.
kick
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
"
he smells
"
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /ban a user without a reason.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
ban
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/ban @bob:matrix.org
"
);
expect
(
matrixService
.
ban
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
undefined
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /ban a user with a reason.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
ban
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/ban @bob:matrix.org he smells
"
);
expect
(
matrixService
.
ban
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
"
he smells
"
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /unban a user.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
unban
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/unban @bob:matrix.org
"
);
expect
(
matrixService
.
unban
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /op a user.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
setUserPowerLevel
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/op @bob:matrix.org 50
"
);
expect
(
matrixService
.
setUserPowerLevel
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
50
,
testPowerLevelsEvent
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
it
(
'
should be able to /deop a user.
'
,
inject
(
function
(
commandsService
)
{
spyOn
(
matrixService
,
'
setUserPowerLevel
'
).
and
.
returnValue
(
testMatrixServicePromise
);
var
promise
=
commandsService
.
processInput
(
roomId
,
"
/deop @bob:matrix.org
"
);
expect
(
matrixService
.
setUserPowerLevel
).
toHaveBeenCalledWith
(
roomId
,
"
@bob:matrix.org
"
,
undefined
,
testPowerLevelsEvent
);
expect
(
promise
).
toBe
(
testMatrixServicePromise
);
}));
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment