Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
d48172e9
Unverified
Commit
d48172e9
authored
1 year ago
by
Kagami Sascha Rosylight
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor(backend/test): add `interface UserToken` (#11050)
parent
58a898df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/backend/test/utils.ts
+19
-17
19 additions, 17 deletions
packages/backend/test/utils.ts
with
19 additions
and
17 deletions
packages/backend/test/utils.ts
+
19
−
17
View file @
d48172e9
...
...
@@ -13,14 +13,16 @@ import type * as misskey from 'misskey-js';
export
{
server
as
startServer
}
from
'
@/boot/common.js
'
;
interface
UserToken
{
token
:
string
}
const
config
=
loadConfig
();
export
const
port
=
config
.
port
;
export
const
cookie
=
(
me
:
any
):
string
=>
{
export
const
cookie
=
(
me
:
UserToken
):
string
=>
{
return
`token=
${
me
.
token
}
;`
;
};
export
const
api
=
async
(
endpoint
:
string
,
params
:
any
,
me
?:
any
)
=>
{
export
const
api
=
async
(
endpoint
:
string
,
params
:
any
,
me
?:
UserToken
)
=>
{
const
normalized
=
endpoint
.
replace
(
/^
\/
/
,
''
);
return
await
request
(
`api/
${
normalized
}
`
,
params
,
me
);
};
...
...
@@ -28,7 +30,7 @@ export const api = async (endpoint: string, params: any, me?: any) => {
export
type
ApiRequest
=
{
endpoint
:
string
,
parameters
:
object
,
user
:
object
|
undefined
,
user
:
UserToken
|
undefined
,
};
export
const
successfulApiCall
=
async
<
T
,
>
(
request
:
ApiRequest
,
assertion
:
{
...
...
@@ -55,7 +57,7 @@ export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
return
res
.
body
;
};
const
request
=
async
(
path
:
string
,
params
:
any
,
me
?:
any
):
Promise
<
{
body
:
any
,
status
:
number
}
>
=>
{
const
request
=
async
(
path
:
string
,
params
:
any
,
me
?:
UserToken
):
Promise
<
{
body
:
any
,
status
:
number
}
>
=>
{
const
auth
=
me
?
{
i
:
me
.
token
,
}
:
{};
...
...
@@ -94,7 +96,7 @@ export const signup = async (params?: Partial<misskey.Endpoints['signup']['req']
return
res
.
body
;
};
export
const
post
=
async
(
user
:
any
,
params
?:
misskey
.
Endpoints
[
'
notes/create
'
][
'
req
'
]):
Promise
<
misskey
.
entities
.
Note
>
=>
{
export
const
post
=
async
(
user
:
UserToken
,
params
?:
misskey
.
Endpoints
[
'
notes/create
'
][
'
req
'
]):
Promise
<
misskey
.
entities
.
Note
>
=>
{
const
q
=
params
;
const
res
=
await
api
(
'
notes/create
'
,
q
,
user
);
...
...
@@ -117,21 +119,21 @@ export const hiddenNote = (note: any): any => {
return
temp
;
};
export
const
react
=
async
(
user
:
any
,
note
:
any
,
reaction
:
string
):
Promise
<
any
>
=>
{
export
const
react
=
async
(
user
:
UserToken
,
note
:
any
,
reaction
:
string
):
Promise
<
any
>
=>
{
await
api
(
'
notes/reactions/create
'
,
{
noteId
:
note
.
id
,
reaction
:
reaction
,
},
user
);
};
export
const
userList
=
async
(
user
:
any
,
userList
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
userList
=
async
(
user
:
UserToken
,
userList
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
users/lists/create
'
,
{
name
:
'
test
'
,
},
user
);
return
res
.
body
;
};
export
const
page
=
async
(
user
:
any
,
page
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
page
=
async
(
user
:
UserToken
,
page
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
pages/create
'
,
{
alignCenter
:
false
,
content
:
[
...
...
@@ -154,7 +156,7 @@ export const page = async (user: any, page: any = {}): Promise<any> => {
return
res
.
body
;
};
export
const
play
=
async
(
user
:
any
,
play
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
play
=
async
(
user
:
UserToken
,
play
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
flash/create
'
,
{
permissions
:
[],
script
:
'
test
'
,
...
...
@@ -165,7 +167,7 @@ export const play = async (user: any, play: any = {}): Promise<any> => {
return
res
.
body
;
};
export
const
clip
=
async
(
user
:
any
,
clip
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
clip
=
async
(
user
:
UserToken
,
clip
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
clips/create
'
,
{
description
:
null
,
isPublic
:
true
,
...
...
@@ -175,7 +177,7 @@ export const clip = async (user: any, clip: any = {}): Promise<any> => {
return
res
.
body
;
};
export
const
galleryPost
=
async
(
user
:
any
,
channel
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
galleryPost
=
async
(
user
:
UserToken
,
channel
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
gallery/posts/create
'
,
{
description
:
null
,
fileIds
:
[],
...
...
@@ -186,7 +188,7 @@ export const galleryPost = async (user: any, channel: any = {}): Promise<any> =>
return
res
.
body
;
};
export
const
channel
=
async
(
user
:
any
,
channel
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
channel
=
async
(
user
:
UserToken
,
channel
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
channels/create
'
,
{
bannerId
:
null
,
description
:
null
,
...
...
@@ -196,7 +198,7 @@ export const channel = async (user: any, channel: any = {}): Promise<any> => {
return
res
.
body
;
};
export
const
role
=
async
(
user
:
any
,
role
:
any
=
{},
policies
:
any
=
{}):
Promise
<
any
>
=>
{
export
const
role
=
async
(
user
:
UserToken
,
role
:
any
=
{},
policies
:
any
=
{}):
Promise
<
any
>
=>
{
const
res
=
await
api
(
'
admin/roles/create
'
,
{
asBadge
:
false
,
canEditMembersByModerator
:
false
,
...
...
@@ -239,7 +241,7 @@ interface UploadOptions {
* Upload file
* @param user User
*/
export
const
uploadFile
=
async
(
user
:
any
,
{
path
,
name
,
blob
}:
UploadOptions
=
{}):
Promise
<
any
>
=>
{
export
const
uploadFile
=
async
(
user
:
UserToken
,
{
path
,
name
,
blob
}:
UploadOptions
=
{}):
Promise
<
any
>
=>
{
const
absPath
=
path
==
null
?
new
URL
(
'
resources/Lenna.jpg
'
,
import
.
meta
.
url
)
:
isAbsolute
(
path
.
toString
())
...
...
@@ -268,7 +270,7 @@ export const uploadFile = async (user: any, { path, name, blob }: UploadOptions
};
};
export
const
uploadUrl
=
async
(
user
:
any
,
url
:
string
)
=>
{
export
const
uploadUrl
=
async
(
user
:
UserToken
,
url
:
string
)
=>
{
let
file
:
any
;
const
marker
=
Math
.
random
().
toString
();
...
...
@@ -290,7 +292,7 @@ export const uploadUrl = async (user: any, url: string) => {
return
file
;
};
export
function
connectStream
(
user
:
any
,
channel
:
string
,
listener
:
(
message
:
Record
<
string
,
any
>
)
=>
any
,
params
?:
any
):
Promise
<
WebSocket
>
{
export
function
connectStream
(
user
:
UserToken
,
channel
:
string
,
listener
:
(
message
:
Record
<
string
,
any
>
)
=>
any
,
params
?:
any
):
Promise
<
WebSocket
>
{
return
new
Promise
((
res
,
rej
)
=>
{
const
ws
=
new
WebSocket
(
`ws://127.0.0.1:
${
port
}
/streaming?i=
${
user
.
token
}
`
);
...
...
@@ -317,7 +319,7 @@ export function connectStream(user: any, channel: string, listener: (message: Re
});
}
export
const
waitFire
=
async
(
user
:
any
,
channel
:
string
,
trgr
:
()
=>
any
,
cond
:
(
msg
:
Record
<
string
,
any
>
)
=>
boolean
,
params
?:
any
)
=>
{
export
const
waitFire
=
async
(
user
:
UserToken
,
channel
:
string
,
trgr
:
()
=>
any
,
cond
:
(
msg
:
Record
<
string
,
any
>
)
=>
boolean
,
params
?:
any
)
=>
{
return
new
Promise
<
boolean
>
(
async
(
res
,
rej
)
=>
{
let
timer
:
NodeJS
.
Timeout
|
null
=
null
;
...
...
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