tests: move mocks to tests/*
This commit is contained in:
@@ -8,7 +8,7 @@ import sgit from "simple-git"
|
||||
import processes from "child_process"
|
||||
import metrics from "../metrics/index.mjs"
|
||||
import setup from "../metrics/setup.mjs"
|
||||
import mocks from "../mocks/index.mjs"
|
||||
import mocks from "../../../tests/mocks/index.mjs"
|
||||
process.on("unhandledRejection", error => {
|
||||
throw error
|
||||
})
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
# Overrides enforced rules for mocks
|
||||
rules:
|
||||
max-params: off
|
||||
no-unused-vars: off
|
||||
@@ -1,160 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Last.fm api
|
||||
if (/^https:..ws.audioscrobbler.com.*$/.test(url)) {
|
||||
//Get recently played tracks
|
||||
if (/user.getrecenttracks/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
|
||||
const artist = faker.random.word()
|
||||
const album = faker.random.words(3)
|
||||
const track = faker.random.words(5)
|
||||
const date = faker.date.recent()
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
recenttracks:{
|
||||
"@attr":{
|
||||
page:"1",
|
||||
perPage:"1",
|
||||
user:"RJ",
|
||||
total:"100",
|
||||
pages:"100",
|
||||
},
|
||||
track:[
|
||||
{
|
||||
artist:{
|
||||
mbid:"",
|
||||
"#text":artist,
|
||||
},
|
||||
album:{
|
||||
mbid:"",
|
||||
"#text":album,
|
||||
},
|
||||
image:[
|
||||
{
|
||||
size:"small",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"medium",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"large",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"extralarge",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
],
|
||||
streamable:"0",
|
||||
date:{
|
||||
uts:Math.floor(date.getTime() / 1000),
|
||||
"#text":date.toUTCString().slice(5, 22),
|
||||
},
|
||||
url:faker.internet.url(),
|
||||
name:track,
|
||||
mbid:"",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
else if (/user.gettoptracks/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
|
||||
const artist = faker.random.word()
|
||||
const track = faker.random.words(5)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
toptracks:{
|
||||
"@attr":{
|
||||
page:"1",
|
||||
perPage:"1",
|
||||
user:"RJ",
|
||||
total:"100",
|
||||
pages:"100",
|
||||
},
|
||||
track:[
|
||||
{
|
||||
artist:{
|
||||
mbid:"",
|
||||
name:artist,
|
||||
},
|
||||
image:[
|
||||
{
|
||||
size:"small",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"medium",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"large",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"extralarge",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
],
|
||||
url:faker.internet.url(),
|
||||
name:track,
|
||||
mbid:"",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
else if (/user.gettopartists/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking lastfm api result > ${url}`)
|
||||
const artist = faker.random.word()
|
||||
const playcount = faker.random.number()
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
topartists:{
|
||||
"@attr":{
|
||||
page:"1",
|
||||
perPage:"1",
|
||||
user:"RJ",
|
||||
total:"100",
|
||||
pages:"100",
|
||||
},
|
||||
artist:[
|
||||
{
|
||||
image:[
|
||||
{
|
||||
size:"small",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"medium",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"large",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
{
|
||||
size:"extralarge",
|
||||
"#text":faker.image.abstract(),
|
||||
},
|
||||
],
|
||||
streamable:"0",
|
||||
playcount,
|
||||
url:faker.internet.url(),
|
||||
name:artist,
|
||||
mbid:"",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url}) {
|
||||
//Last.fm api
|
||||
if (/^https:..testapp.herokuapp.com.*$/.test(url)) {
|
||||
//Get Nightscout Data
|
||||
console.debug(`metrics/compute/mocks > mocking nightscout api result > ${url}`)
|
||||
const lastInterval = Math.floor(new Date() / 300000) * 300000
|
||||
return ({
|
||||
status:200,
|
||||
data:new Array(12).fill(null).map(_ => ({
|
||||
_id:faker.git.commitSha().substring(0, 23),
|
||||
device:"xDrip-DexcomG5",
|
||||
date:lastInterval,
|
||||
dateString:new Date(lastInterval).toISOString(),
|
||||
sgv:faker.datatype.number({min:40, max:400}),
|
||||
delta:faker.datatype.number({min:-10, max:10}),
|
||||
direction:faker.random.arrayElement(["SingleUp", "DoubleUp", "FortyFiveUp", "Flat", "FortyFiveDown", "SingleDown", "DoubleDown"]),
|
||||
type:"sgv",
|
||||
filtered:0,
|
||||
unfiltered:0,
|
||||
rssi:100,
|
||||
noise:1,
|
||||
sysTime:new Date(lastInterval).toISOString(),
|
||||
utcOffset:faker.datatype.number({min:-12, max:14}) * 60,
|
||||
})),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Tested url
|
||||
const tested = url.match(/&url=(?<tested>.*?)(?:&|$)/)?.groups?.tested ?? faker.internet.url()
|
||||
//Pagespeed api
|
||||
if (/^https:..www.googleapis.com.pagespeedonline.v5.*$/.test(url)) {
|
||||
//Pagespeed result
|
||||
if (/v5.runPagespeed.*&key=MOCKED_TOKEN/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking pagespeed api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
captchaResult:"CAPTCHA_NOT_NEEDED",
|
||||
id:tested,
|
||||
lighthouseResult:{
|
||||
requestedUrl:tested,
|
||||
finalUrl:tested,
|
||||
lighthouseVersion:"6.3.0",
|
||||
audits:{
|
||||
"final-screenshot":{
|
||||
id:"final-screenshot",
|
||||
title:"Final Screenshot",
|
||||
score:null,
|
||||
details:{
|
||||
data:null,
|
||||
type:"screenshot",
|
||||
timestamp:Date.now(),
|
||||
},
|
||||
},
|
||||
metrics:{
|
||||
id:"metrics",
|
||||
title:"Metrics",
|
||||
score:null,
|
||||
details:{
|
||||
items:[
|
||||
{
|
||||
observedFirstContentfulPaint:faker.datatype.number(500),
|
||||
observedFirstVisualChangeTs:faker.time.recent(),
|
||||
observedFirstContentfulPaintTs:faker.time.recent(),
|
||||
firstContentfulPaint:faker.datatype.number(500),
|
||||
observedDomContentLoaded:faker.datatype.number(500),
|
||||
observedFirstMeaningfulPaint:faker.datatype.number(1000),
|
||||
maxPotentialFID:faker.datatype.number(500),
|
||||
observedLoad:faker.datatype.number(500),
|
||||
firstMeaningfulPaint:faker.datatype.number(500),
|
||||
observedCumulativeLayoutShift:faker.datatype.float({max:1}),
|
||||
observedSpeedIndex:faker.datatype.number(1000),
|
||||
observedSpeedIndexTs:faker.time.recent(),
|
||||
observedTimeOriginTs:faker.time.recent(),
|
||||
observedLargestContentfulPaint:faker.datatype.number(1000),
|
||||
cumulativeLayoutShift:faker.datatype.float({max:1}),
|
||||
observedFirstPaintTs:faker.time.recent(),
|
||||
observedTraceEndTs:faker.time.recent(),
|
||||
largestContentfulPaint:faker.datatype.number(2000),
|
||||
observedTimeOrigin:faker.datatype.number(10),
|
||||
speedIndex:faker.datatype.number(1000),
|
||||
observedTraceEnd:faker.datatype.number(2000),
|
||||
observedDomContentLoadedTs:faker.time.recent(),
|
||||
observedFirstPaint:faker.datatype.number(500),
|
||||
totalBlockingTime:faker.datatype.number(500),
|
||||
observedLastVisualChangeTs:faker.time.recent(),
|
||||
observedFirstVisualChange:faker.datatype.number(500),
|
||||
observedLargestContentfulPaintTs:faker.time.recent(),
|
||||
estimatedInputLatency:faker.datatype.number(100),
|
||||
observedLoadTs:faker.time.recent(),
|
||||
observedLastVisualChange:faker.datatype.number(1000),
|
||||
firstCPUIdle:faker.datatype.number(1000),
|
||||
interactive:faker.datatype.number(1000),
|
||||
observedNavigationStartTs:faker.time.recent(),
|
||||
observedNavigationStart:faker.datatype.number(10),
|
||||
observedFirstMeaningfulPaintTs:faker.time.recent(),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
categories:{
|
||||
"best-practices":{
|
||||
id:"best-practices",
|
||||
title:"Best Practices",
|
||||
score:faker.datatype.float({max:1}),
|
||||
},
|
||||
seo:{
|
||||
id:"seo",
|
||||
title:"SEO",
|
||||
score:faker.datatype.float({max:1}),
|
||||
},
|
||||
accessibility:{
|
||||
id:"accessibility",
|
||||
title:"Accessibility",
|
||||
score:faker.datatype.float({max:1}),
|
||||
},
|
||||
performance:{
|
||||
id:"performance",
|
||||
title:"Performance",
|
||||
score:faker.datatype.float({max:1}),
|
||||
},
|
||||
},
|
||||
},
|
||||
analysisUTCTimestamp:`${faker.date.recent()}`,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Wakatime api
|
||||
if (/^https:..api.poopmap.net$/.test(url)) {
|
||||
//Get user profile
|
||||
if (/public_links\/MOCKED_TOKEN/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking poopmap api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
poops:new Array(12 + faker.datatype.number(6)).fill(null).map(_ => ({
|
||||
id:79744699,
|
||||
latitude:faker.address.latitude(),
|
||||
longitude:faker.address.longitude(),
|
||||
created_at:faker.date.past().toISOString(),
|
||||
note:"",
|
||||
place:"",
|
||||
rating:faker.datatype.number(5),
|
||||
followers_count:faker.datatype.number(100),
|
||||
comments_count:faker.datatype.number(12)
|
||||
}))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Spotify api
|
||||
if (/^https:..api.spotify.com.*$/.test(url)) {
|
||||
//Get recently played tracks
|
||||
if (/me.player.recently-played/.test(url) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
|
||||
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
|
||||
const artist = faker.random.words()
|
||||
const track = faker.random.words(5)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:[
|
||||
{
|
||||
track:{
|
||||
album:{
|
||||
album_type:"single",
|
||||
artists:[
|
||||
{
|
||||
name:artist,
|
||||
type:"artist",
|
||||
},
|
||||
],
|
||||
images:[
|
||||
{
|
||||
height:640,
|
||||
url:faker.image.abstract(),
|
||||
width:640,
|
||||
},
|
||||
{
|
||||
height:300,
|
||||
url:faker.image.abstract(),
|
||||
width:300,
|
||||
},
|
||||
{
|
||||
height:64,
|
||||
url:faker.image.abstract(),
|
||||
width:64,
|
||||
},
|
||||
],
|
||||
name:track,
|
||||
release_date:`${faker.date.past()}`.substring(0, 10),
|
||||
type:"album",
|
||||
},
|
||||
artists:[
|
||||
{
|
||||
name:artist,
|
||||
type:"artist",
|
||||
},
|
||||
],
|
||||
name:track,
|
||||
preview_url:faker.internet.url(),
|
||||
type:"track",
|
||||
},
|
||||
played_at:`${faker.date.recent()}`,
|
||||
context:{
|
||||
type:"album",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
else if (/me.top.tracks/.test(url) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
|
||||
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
|
||||
const artist = faker.random.words()
|
||||
const track = faker.random.words(5)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:[
|
||||
{
|
||||
album:{
|
||||
album_type:"single",
|
||||
artists:[
|
||||
{
|
||||
name:artist,
|
||||
type:"artist",
|
||||
},
|
||||
],
|
||||
images:[
|
||||
{
|
||||
height:640,
|
||||
url:faker.image.abstract(),
|
||||
width:640,
|
||||
},
|
||||
{
|
||||
height:300,
|
||||
url:faker.image.abstract(),
|
||||
width:300,
|
||||
},
|
||||
{
|
||||
height:64,
|
||||
url:faker.image.abstract(),
|
||||
width:64,
|
||||
},
|
||||
],
|
||||
name:track,
|
||||
release_date:`${faker.date.past()}`.substring(0, 10),
|
||||
type:"album",
|
||||
},
|
||||
artists:[
|
||||
{
|
||||
name:artist,
|
||||
type:"artist",
|
||||
},
|
||||
],
|
||||
name:track,
|
||||
preview_url:faker.internet.url(),
|
||||
type:"track",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
else if (/me.top.artists/.test(url) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN_ACCESS")) {
|
||||
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
|
||||
const genre = faker.random.words()
|
||||
const track = faker.random.words(5)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:[
|
||||
{
|
||||
genres: [genre],
|
||||
images:[
|
||||
{
|
||||
height:640,
|
||||
url:faker.image.abstract(),
|
||||
width:640,
|
||||
},
|
||||
{
|
||||
height:300,
|
||||
url:faker.image.abstract(),
|
||||
width:300,
|
||||
},
|
||||
{
|
||||
height:64,
|
||||
url:faker.image.abstract(),
|
||||
width:64,
|
||||
},
|
||||
],
|
||||
name:track,
|
||||
type:"artist",
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Stackoverflow api
|
||||
if (/^https:..api.stackexchange.com.2.2.*$/.test(url)) {
|
||||
//Extract user id
|
||||
const user_id = url.match(/[/]users[/](?<id>\d+)/)?.groups?.id ?? NaN
|
||||
const pagesize = Number(url.match(/pagesize=(?<pagesize>\d+)/)?.groups?.pagesize) || 30
|
||||
//User account
|
||||
if (/users[/]\d+[/][?]site=stackoverflow$/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking stackoverflow api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:[
|
||||
{
|
||||
badge_counts:{bronze:faker.datatype.number(500), silver:faker.datatype.number(300), gold:faker.datatype.number(100)},
|
||||
accept_rate:faker.datatype.number(100),
|
||||
answer_count:faker.datatype.number(1000),
|
||||
question_count:faker.datatype.number(1000),
|
||||
view_count:faker.datatype.number(10000),
|
||||
creation_date:faker.date.past(),
|
||||
display_name:faker.internet.userName(),
|
||||
user_id,
|
||||
reputation:faker.datatype.number(100000),
|
||||
},
|
||||
],
|
||||
has_more:false,
|
||||
quota_max:300,
|
||||
quota_remaining:faker.datatype.number(300),
|
||||
},
|
||||
})
|
||||
}
|
||||
//Total metrics
|
||||
if (/[?]site=stackoverflow&filter=total$/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking stackoverflow api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
total:faker.datatype.number(10000),
|
||||
},
|
||||
})
|
||||
}
|
||||
//Questions
|
||||
if ((/questions[?]site=stackoverflow/.test(url)) || (/questions[/][\d;]+[?]site=stackoverflow/.test(url))) {
|
||||
console.debug(`metrics/compute/mocks > mocking stackoverflow api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:new Array(pagesize).fill(null).map(_ => ({
|
||||
tags:new Array(5).fill(null).map(_ => faker.lorem.slug()),
|
||||
owner:{display_name:faker.internet.userName()},
|
||||
is_answered:faker.datatype.boolean(),
|
||||
view_count:faker.datatype.number(10000),
|
||||
accepted_answer_id:faker.datatype.number(1000000),
|
||||
answer_count:faker.datatype.number(100),
|
||||
score:faker.datatype.number(1000),
|
||||
creation_date:faker.time.recent(),
|
||||
down_vote_count:faker.datatype.number(1000),
|
||||
up_vote_count:faker.datatype.number(1000),
|
||||
comment_count:faker.datatype.number(1000),
|
||||
favorite_count:faker.datatype.number(1000),
|
||||
title:faker.lorem.sentence(),
|
||||
body_markdown:faker.lorem.paragraphs(),
|
||||
link:faker.internet.url(),
|
||||
question_id:faker.datatype.number(1000000),
|
||||
})),
|
||||
has_more:false,
|
||||
quota_max:300,
|
||||
quota_remaining:faker.datatype.number(300),
|
||||
},
|
||||
})
|
||||
}
|
||||
//Answers
|
||||
if ((/answers[?]site=stackoverflow/.test(url)) || (/answers[/][\d;]+[?]site=stackoverflow/.test(url))) {
|
||||
console.debug(`metrics/compute/mocks > mocking stackoverflow api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
items:new Array(pagesize).fill(null).map(_ => ({
|
||||
owner:{display_name:faker.internet.userName()},
|
||||
link:faker.internet.url(),
|
||||
is_accepted:faker.datatype.boolean(),
|
||||
score:faker.datatype.number(1000),
|
||||
down_vote_count:faker.datatype.number(1000),
|
||||
up_vote_count:faker.datatype.number(1000),
|
||||
comment_count:faker.datatype.number(1000),
|
||||
creation_date:faker.time.recent(),
|
||||
question_id:faker.datatype.number(1000000),
|
||||
body_markdown:faker.lorem.paragraphs(),
|
||||
answer_id:faker.datatype.number(1000000),
|
||||
})),
|
||||
has_more:false,
|
||||
quota_max:300,
|
||||
quota_remaining:faker.datatype.number(300),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Twitter api
|
||||
if (/^https:..api.twitter.com.*$/.test(url)) {
|
||||
//Get user profile
|
||||
if ((/users.by.username/.test(url)) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN")) {
|
||||
console.debug(`metrics/compute/mocks > mocking twitter api result > ${url}`)
|
||||
const username = url.match(/username[/](?<username>.*?)[?]/)?.groups?.username ?? faker.internet.userName()
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
profile_image_url:faker.image.people(),
|
||||
name:faker.name.findName(),
|
||||
verified:faker.datatype.boolean(),
|
||||
id:faker.datatype.number(1000000).toString(),
|
||||
username,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
//Get recent tweets
|
||||
if ((/tweets.search.recent/.test(url)) && (options?.headers?.Authorization === "Bearer MOCKED_TOKEN")) {
|
||||
console.debug(`metrics/compute/mocks > mocking twitter api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:[
|
||||
{
|
||||
id:faker.datatype.number(100000000000000).toString(),
|
||||
created_at:`${faker.date.recent()}`,
|
||||
entities:{
|
||||
mentions:[
|
||||
{start:22, end:33, username:"lowlighter"},
|
||||
],
|
||||
},
|
||||
text:"Checkout metrics from @lowlighter ! #GitHub",
|
||||
},
|
||||
{
|
||||
id:faker.datatype.number(100000000000000).toString(),
|
||||
created_at:`${faker.date.recent()}`,
|
||||
text:faker.lorem.paragraph(),
|
||||
},
|
||||
],
|
||||
includes:{
|
||||
users:[
|
||||
{
|
||||
id:faker.datatype.number(100000000000000).toString(),
|
||||
name:"lowlighter",
|
||||
username:"lowlighter",
|
||||
},
|
||||
],
|
||||
},
|
||||
meta:{
|
||||
newest_id:faker.datatype.number(100000000000000).toString(),
|
||||
oldest_id:faker.datatype.number(100000000000000).toString(),
|
||||
result_count:2,
|
||||
next_token:"MOCKED_CURSOR",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Wakatime api
|
||||
if (/^https:..wakatime.com.api.v1.users..*.stats.*$/.test(url)) {
|
||||
//Get user profile
|
||||
if (/api_key=MOCKED_TOKEN/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking wakatime api result > ${url}`)
|
||||
const stats = array => {
|
||||
const elements = []
|
||||
let results = new Array(4 + faker.datatype.number(2)).fill(null).map(_ => ({
|
||||
get digital() {
|
||||
return `${this.hours}:${this.minutes}`
|
||||
},
|
||||
hours:faker.datatype.number(1000),
|
||||
minutes:faker.datatype.number(1000),
|
||||
name:array ? faker.random.arrayElement(array) : faker.random.words(2).replace(/ /g, "-").toLocaleLowerCase(),
|
||||
percent:0,
|
||||
total_seconds:faker.datatype.number(1000000),
|
||||
}))
|
||||
results = results.filter(({name}) => elements.includes(name) ? false : (elements.push(name), true))
|
||||
let percents = 100
|
||||
for (const result of results) {
|
||||
result.percent = 1 + faker.datatype.number(percents - 1)
|
||||
percents -= result.percent
|
||||
}
|
||||
return results
|
||||
}
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
best_day:{
|
||||
created_at:faker.date.recent(),
|
||||
date:`${faker.date.recent()}`.substring(0, 10),
|
||||
total_seconds:faker.datatype.number(1000000),
|
||||
},
|
||||
categories:stats(),
|
||||
daily_average:faker.datatype.number(12 * 60 * 60),
|
||||
daily_average_including_other_language:faker.datatype.number(12 * 60 * 60),
|
||||
dependencies:stats(),
|
||||
editors:stats(["VS Code", "Chrome", "IntelliJ", "PhpStorm", "WebStorm", "Android Studio", "Visual Studio", "Sublime Text", "PyCharm", "Vim", "Atom", "Xcode"]),
|
||||
languages:stats(["JavaScript", "TypeScript", "PHP", "Java", "Python", "Vue.js", "HTML", "C#", "JSON", "Dart", "SCSS", "Kotlin", "JSX", "Go", "Ruby", "YAML"]),
|
||||
machines:stats(),
|
||||
operating_systems:stats(["Mac", "Windows", "Linux"]),
|
||||
project:null,
|
||||
projects:/api_key=MOCKED_TOKEN_NO_PROJECTS/.test(url) ? null : stats(),
|
||||
total_seconds:faker.datatype.number(1000000000),
|
||||
total_seconds_including_other_language:faker.datatype.number(1000000000),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
//Wakatime api
|
||||
if (/^https:..apidojo-yahoo-finance-v1.p.rapidapi.com.stock.v2.*$/.test(url)) {
|
||||
//Get company profile
|
||||
if (/get-profile/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking yahoo finance api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
price:{
|
||||
marketCap:{
|
||||
raw:faker.datatype.number(1000000000),
|
||||
},
|
||||
symbol:"OCTO",
|
||||
},
|
||||
quoteType:{
|
||||
shortName:faker.company.companyName(),
|
||||
longName:faker.company.companyName(),
|
||||
exchangeTimezoneName:faker.address.timeZone(),
|
||||
symbol:"OCTO",
|
||||
},
|
||||
calendarEvents:{},
|
||||
summaryDetail:{},
|
||||
symbol:"OCTO",
|
||||
assetProfile:{
|
||||
fullTimeEmployees:faker.datatype.number(10000),
|
||||
city:faker.address.city(),
|
||||
country:faker.address.country(),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
//Get stock chart
|
||||
if (/get-chart/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking yahoo finance api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
chart:{
|
||||
result:[
|
||||
{
|
||||
meta:{
|
||||
currency:"USD",
|
||||
symbol:"OCTO",
|
||||
regularMarketPrice:faker.datatype.number(10000) / 100,
|
||||
chartPreviousClose:faker.datatype.number(10000) / 100,
|
||||
previousClose:faker.datatype.number(10000) / 100,
|
||||
},
|
||||
timestamp:new Array(1000).fill(Date.now()).map((x, i) => x + i * 60000),
|
||||
indicators:{
|
||||
quote:[
|
||||
{
|
||||
close:new Array(1000).fill(null).map(_ => faker.datatype.number(10000) / 100),
|
||||
get low() {
|
||||
return this.close
|
||||
},
|
||||
get high() {
|
||||
return this.close
|
||||
},
|
||||
get open() {
|
||||
return this.close
|
||||
},
|
||||
volume:[],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, body, login = faker.internet.userName()}) {
|
||||
if (/^https:..graphql.anilist.co.*$/.test(url)) {
|
||||
//Initialization and media generator
|
||||
const {query} = body
|
||||
const media = ({type}) => ({
|
||||
title:{romaji:faker.lorem.words(), english:faker.lorem.words(), native:faker.lorem.words()},
|
||||
description:faker.lorem.paragraphs(),
|
||||
type,
|
||||
status:faker.random.arrayElement(["FINISHED", "RELEASING", "NOT_YET_RELEASED", "CANCELLED", "HIATUS"]),
|
||||
episodes:100 + faker.datatype.number(100),
|
||||
volumes:faker.datatype.number(100),
|
||||
chapters:100 + faker.datatype.number(1000),
|
||||
averageScore:faker.datatype.number(100),
|
||||
countryOfOrigin:"JP",
|
||||
genres:new Array(6).fill(null).map(_ => faker.lorem.word()),
|
||||
coverImage:{medium:null},
|
||||
startDate:{year:faker.date.past(20).getFullYear()},
|
||||
})
|
||||
//User statistics query
|
||||
if (/^query Statistics /.test(query)) {
|
||||
console.debug("metrics/compute/mocks > mocking anilist api result > Statistics")
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
User:{
|
||||
id:faker.datatype.number(100000),
|
||||
name:faker.internet.userName(),
|
||||
about:null,
|
||||
statistics:{
|
||||
anime:{
|
||||
count:faker.datatype.number(1000),
|
||||
minutesWatched:faker.datatype.number(100000),
|
||||
episodesWatched:faker.datatype.number(10000),
|
||||
genres:new Array(4).fill(null).map(_ => ({genre:faker.lorem.word()})),
|
||||
},
|
||||
manga:{
|
||||
count:faker.datatype.number(1000),
|
||||
chaptersRead:faker.datatype.number(100000),
|
||||
volumesRead:faker.datatype.number(10000),
|
||||
genres:new Array(4).fill(null).map(_ => ({genre:faker.lorem.word()})),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
//Favorites characters
|
||||
if (/^query FavoritesCharacters /.test(query)) {
|
||||
console.debug("metrics/compute/mocks > mocking anilist api result > Favorites characters")
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
User:{
|
||||
favourites:{
|
||||
characters:{
|
||||
nodes:new Array(2 + faker.datatype.number(16)).fill(null).map(_ => ({
|
||||
name:{full:faker.name.findName(), native:faker.name.findName()},
|
||||
image:{medium:null},
|
||||
})),
|
||||
pageInfo:{currentPage:1, hasNextPage:false},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
//Favorites anime/manga query
|
||||
if (/^query Favorites /.test(query)) {
|
||||
console.debug("metrics/compute/mocks > mocking anilist api result > Favorites")
|
||||
const type = /anime[(]/.test(query) ? "ANIME" : /manga[(]/.test(query) ? "MANGA" : "OTHER"
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
User:{
|
||||
favourites:{
|
||||
[type.toLocaleLowerCase()]:{
|
||||
nodes:new Array(16).fill(null).map(_ => media({type})),
|
||||
pageInfo:{currentPage:1, hasNextPage:false},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
//Medias query
|
||||
if (/^query Medias /.test(query)) {
|
||||
console.debug("metrics/compute/mocks > mocking anilist api result > Medias")
|
||||
const {type} = body.variables
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
MediaListCollection:{
|
||||
lists:[
|
||||
{
|
||||
name:{ANIME:"Watching", MANGA:"Reading", OTHER:"Completed"}[type],
|
||||
isCustomList:false,
|
||||
entries:new Array(16).fill(null).map(_ => ({
|
||||
status:faker.random.arrayElement(["CURRENT", "PLANNING", "COMPLETED", "DROPPED", "PAUSED", "REPEATING"]),
|
||||
progress:faker.datatype.number(100),
|
||||
progressVolumes:null,
|
||||
score:0,
|
||||
startedAt:{year:null, month:null, day:null},
|
||||
completedAt:{year:null, month:null, day:null},
|
||||
media:media({type}),
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, body, login = faker.internet.userName()}) {
|
||||
if (/^https:..api.hashnode.com.*$/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking hashnode result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
data:{
|
||||
user:{
|
||||
publication:{
|
||||
posts:new Array(30).fill(null).map(_ => ({
|
||||
title:faker.lorem.sentence(),
|
||||
brief:faker.lorem.paragraph(),
|
||||
coverImage:null,
|
||||
dateAdded:faker.date.recent(),
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
//Imports
|
||||
import urls from "url"
|
||||
|
||||
/**Mocked data */
|
||||
export default function({faker, url, body, login = faker.internet.userName()}) {
|
||||
if (/^https:..accounts.spotify.com.api.token.*$/.test(url)) {
|
||||
//Access token generator
|
||||
const params = new urls.URLSearchParams(body)
|
||||
if ((params.get("grant_type") === "refresh_token") && (params.get("client_id") === "MOCKED_CLIENT_ID") && (params.get("client_secret") === "MOCKED_CLIENT_SECRET") && (params.get("refresh_token") === "MOCKED_REFRESH_TOKEN")) {
|
||||
console.debug(`metrics/compute/mocks > mocking spotify api result > ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
data:{
|
||||
access_token:"MOCKED_TOKEN_ACCESS",
|
||||
token_type:"Bearer",
|
||||
expires_in:3600,
|
||||
scope:"user-read-recently-played user-read-private",
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, url, options, login = faker.internet.userName()}) {
|
||||
if (/^https:..music.youtube.com.youtubei.v1.*$/.test(url)) {
|
||||
//Get recently played tracks
|
||||
if (/browse/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking yt music api result > ${url}`)
|
||||
const artist = faker.random.word()
|
||||
const track = faker.random.words(5)
|
||||
const artwork = faker.image.imageUrl()
|
||||
return ({
|
||||
contents:{
|
||||
singleColumnBrowseResultsRenderer:{
|
||||
tabs:[{
|
||||
tabRenderer:{
|
||||
content:{
|
||||
sectionListRenderer:{
|
||||
contents:[{
|
||||
contents:[{
|
||||
musicResponsiveListItemRenderer:{
|
||||
thumbnail:{
|
||||
musicThumbnailRenderer:{
|
||||
thumbnail:{
|
||||
thumbnails:[{
|
||||
url:artwork,
|
||||
}]
|
||||
},
|
||||
}
|
||||
},
|
||||
flexColumns:[{
|
||||
musicResponsiveListItemFlexColumnRenderer:{
|
||||
text:{
|
||||
runs:[{
|
||||
text:track,
|
||||
}]
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
musicResponsiveListItemFlexColumnRenderer:{
|
||||
text:{
|
||||
runs:[{
|
||||
text:artist,
|
||||
}]
|
||||
},
|
||||
}
|
||||
}],
|
||||
}
|
||||
}],
|
||||
}],
|
||||
},
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > achievements/metrics")
|
||||
return ({
|
||||
user:{
|
||||
repositories:{
|
||||
nodes:[
|
||||
{
|
||||
createdAt:faker.date.recent(),
|
||||
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
forks:{
|
||||
nodes:[
|
||||
{
|
||||
createdAt:faker.date.recent(),
|
||||
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
popular:{
|
||||
nodes:[{stargazers:{totalCount:faker.datatype.number(50000)}}],
|
||||
},
|
||||
pullRequests:{
|
||||
nodes:[
|
||||
{
|
||||
createdAt:faker.date.recent(),
|
||||
title:faker.lorem.sentence(),
|
||||
repository:{nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`},
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(50000),
|
||||
},
|
||||
contributionsCollection:{
|
||||
pullRequestReviewContributions:{
|
||||
nodes:[
|
||||
{
|
||||
occurredAt:faker.date.recent(),
|
||||
pullRequest:{
|
||||
title:faker.lorem.sentence(),
|
||||
number:faker.datatype.number(1000),
|
||||
repository:{nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`},
|
||||
},
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(1000),
|
||||
},
|
||||
},
|
||||
projects:{totalCount:faker.datatype.number(100)},
|
||||
packages:{totalCount:faker.datatype.number(100)},
|
||||
organizations:{nodes:[], totalCount:faker.datatype.number(5)},
|
||||
gists:{
|
||||
nodes:[{createdAt:faker.date.recent(), name:faker.lorem.slug()}],
|
||||
totalCount:faker.datatype.number(1000),
|
||||
},
|
||||
starredRepositories:{totalCount:faker.datatype.number(1000)},
|
||||
followers:{totalCount:faker.datatype.number(10000)},
|
||||
following:{totalCount:faker.datatype.number(10000)},
|
||||
bio:faker.lorem.sentence(),
|
||||
status:{message:faker.lorem.paragraph()},
|
||||
sponsorshipsAsSponsor:{totalCount:faker.datatype.number(100)},
|
||||
discussionsStarted:{totalCount:faker.datatype.number(1000)},
|
||||
discussionsComments:{totalCount:faker.datatype.number(1000)},
|
||||
discussionAnswers:{totalCount:faker.datatype.number(1000)},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > achievements/metrics")
|
||||
return ({
|
||||
repository:{viewerHasStarred:faker.datatype.boolean()},
|
||||
viewer:{login},
|
||||
})
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > achievements/octocat")
|
||||
return ({
|
||||
user:{viewerIsFollowing:faker.datatype.boolean()},
|
||||
viewer:{login},
|
||||
})
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > achievements/organizations")
|
||||
return ({
|
||||
organization:{
|
||||
repositories:{
|
||||
nodes:[
|
||||
{
|
||||
createdAt:faker.date.recent(),
|
||||
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
forks:{
|
||||
nodes:[
|
||||
{
|
||||
createdAt:faker.date.recent(),
|
||||
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
popular:{
|
||||
nodes:[{stargazers:{totalCount:faker.datatype.number(50000)}}],
|
||||
},
|
||||
projects:{totalCount:faker.datatype.number(100)},
|
||||
packages:{totalCount:faker.datatype.number(100)},
|
||||
membersWithRole:{totalCount:faker.datatype.number(100)},
|
||||
sponsorshipsAsSponsor:{totalCount:faker.datatype.number(100)},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > achievements/ranking")
|
||||
return ({
|
||||
repo_rank:{repositoryCount:faker.datatype.number(100000)},
|
||||
forks_rank:{repositoryCount:faker.datatype.number(100000)},
|
||||
created_rank:{userCount:faker.datatype.number(100000)},
|
||||
user_rank:{userCount:faker.datatype.number(100000)},
|
||||
repo_total:{repositoryCount:faker.datatype.number(100000)},
|
||||
user_total:{userCount:faker.datatype.number(100000)},
|
||||
})
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/user")
|
||||
return ({
|
||||
user:{
|
||||
calendar:{
|
||||
contributionCalendar:{
|
||||
weeks:[
|
||||
{
|
||||
contributionDays:[
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
],
|
||||
},
|
||||
{
|
||||
contributionDays:[
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
],
|
||||
},
|
||||
{
|
||||
contributionDays:[
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
{color:faker.random.arrayElement(["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"])},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/user")
|
||||
return ({
|
||||
user:{
|
||||
contributionsCollection:{
|
||||
totalRepositoriesWithContributedCommits:faker.datatype.number(100),
|
||||
totalCommitContributions:faker.datatype.number(10000),
|
||||
restrictedContributionsCount:faker.datatype.number(10000),
|
||||
totalIssueContributions:faker.datatype.number(100),
|
||||
totalPullRequestContributions:faker.datatype.number(1000),
|
||||
totalPullRequestReviewContributions:faker.datatype.number(1000),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/user")
|
||||
return ({
|
||||
user:{
|
||||
packages:{totalCount:faker.datatype.number(10)},
|
||||
starredRepositories:{totalCount:faker.datatype.number(1000)},
|
||||
watching:{totalCount:faker.datatype.number(100)},
|
||||
sponsorshipsAsSponsor:{totalCount:faker.datatype.number(10)},
|
||||
sponsorshipsAsMaintainer:{totalCount:faker.datatype.number(10)},
|
||||
repositoriesContributedTo:{totalCount:faker.datatype.number(100)},
|
||||
followers:{totalCount:faker.datatype.number(1000)},
|
||||
following:{totalCount:faker.datatype.number(1000)},
|
||||
issueComments:{totalCount:faker.datatype.number(1000)},
|
||||
organizations:{totalCount:faker.datatype.number(10)},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/user")
|
||||
return ({
|
||||
user:{
|
||||
repositories:{totalCount:faker.datatype.number(100), totalDiskUsage:faker.datatype.number(100000)},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/repositories")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
get repositoriesContributedTo() {
|
||||
return this.repositories
|
||||
},
|
||||
repositories:{
|
||||
edges:[],
|
||||
nodes:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
get repositoriesContributedTo() {
|
||||
return this.repositories
|
||||
},
|
||||
repositories:{
|
||||
edges:[
|
||||
{
|
||||
cursor:"MOCKED_CURSOR",
|
||||
},
|
||||
],
|
||||
nodes:[
|
||||
{
|
||||
name:faker.random.words(),
|
||||
watchers:{totalCount:faker.datatype.number(1000)},
|
||||
stargazers:{totalCount:faker.datatype.number(10000)},
|
||||
owner:{login},
|
||||
languages:{
|
||||
edges:[
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
],
|
||||
},
|
||||
issues_open:{totalCount:faker.datatype.number(100)},
|
||||
issues_closed:{totalCount:faker.datatype.number(100)},
|
||||
pr_open:{totalCount:faker.datatype.number(100)},
|
||||
pr_closed:{totalCount:faker.datatype.number(100)},
|
||||
pr_merged:{totalCount:faker.datatype.number(100)},
|
||||
releases:{totalCount:faker.datatype.number(100)},
|
||||
forkCount:faker.datatype.number(100),
|
||||
licenseInfo:{spdxId:"MIT"},
|
||||
deployments:{totalCount:faker.datatype.number(100)},
|
||||
environments:{totalCount:faker.datatype.number(100)},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/repository")
|
||||
return ({
|
||||
user:{
|
||||
repository:{
|
||||
name:"metrics",
|
||||
owner:{login},
|
||||
createdAt:new Date().toISOString(),
|
||||
diskUsage:Math.floor(Math.random() * 10000),
|
||||
homepageUrl:faker.internet.url(),
|
||||
watchers:{totalCount:faker.datatype.number(1000)},
|
||||
stargazers:{totalCount:faker.datatype.number(10000)},
|
||||
languages:{
|
||||
edges:[
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
{size:faker.datatype.number(100000), node:{color:faker.internet.color(), name:faker.lorem.word()}},
|
||||
],
|
||||
},
|
||||
issues_open:{totalCount:faker.datatype.number(100)},
|
||||
issues_closed:{totalCount:faker.datatype.number(100)},
|
||||
pr_open:{totalCount:faker.datatype.number(100)},
|
||||
pr_closed:{totalCount:faker.datatype.number(100)},
|
||||
pr_merged:{totalCount:faker.datatype.number(100)},
|
||||
releases:{totalCount:faker.datatype.number(100)},
|
||||
forkCount:faker.datatype.number(100),
|
||||
licenseInfo:{spdxId:"MIT"},
|
||||
deployments:{totalCount:faker.datatype.number(100)},
|
||||
environments:{totalCount:faker.datatype.number(100)},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > base/user")
|
||||
return ({
|
||||
user:{
|
||||
databaseId:faker.datatype.number(10000000),
|
||||
name:faker.name.findName(),
|
||||
login,
|
||||
createdAt:`${faker.date.past(10)}`,
|
||||
avatarUrl:faker.image.people(),
|
||||
websiteUrl:faker.internet.url(),
|
||||
isHireable:faker.datatype.boolean(),
|
||||
twitterUsername:login,
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > contributors/commit")
|
||||
return ({
|
||||
repository:{
|
||||
object:{
|
||||
oid:"MOCKED_SHA",
|
||||
abbreviatedOid:"MOCKED_SHA",
|
||||
messageHeadline:faker.lorem.sentence(),
|
||||
committedDate:faker.date.recent(),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > discussions/categories")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
repositoryDiscussions:{
|
||||
edges:[],
|
||||
nodes:[],
|
||||
}
|
||||
}
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
repositoryDiscussions:{
|
||||
edges:new Array(100).fill(null).map(_ => ({cursor:"MOCKED_CURSOR"})),
|
||||
nodes:new Array(100).fill(null).map(_ => ({
|
||||
category:{
|
||||
emoji:faker.random.arrayElement([":chart_with_upwards_trend:", ":chart_with_downwards_trend:", ":bar_char:"]),
|
||||
name:faker.lorem.slug()
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > discussions/comments")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
repositoryDiscussionsComments:{
|
||||
edges:[],
|
||||
nodes:[],
|
||||
}
|
||||
}
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
repositoryDiscussionsComments:{
|
||||
edges:new Array(100).fill(null).map(_ => ({cursor:"MOCKED_CURSOR"})),
|
||||
nodes:new Array(100).fill(null).map(_ => ({upvoteCount: faker.datatype.number(10)}))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > discussions/statistics")
|
||||
return ({
|
||||
user:{
|
||||
started:{totalCount:faker.datatype.number(1000)},
|
||||
comments:{totalCount:faker.datatype.number(1000)},
|
||||
answers:{totalCount:faker.datatype.number(1000)}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > followup/repository/collaborators")
|
||||
return ({
|
||||
repository:{
|
||||
collaborators:{
|
||||
nodes:["github-user"]
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > followup/repository")
|
||||
return ({
|
||||
issues_open:{issueCount:faker.datatype.number(100)},
|
||||
issues_drafts:{issueCount:faker.datatype.number(100)},
|
||||
issues_skipped:{issueCount:faker.datatype.number(100)},
|
||||
issues_closed:{issueCount:faker.datatype.number(100)},
|
||||
pr_open:{issueCount:faker.datatype.number(100)},
|
||||
pr_drafts:{issueCount:faker.datatype.number(100)},
|
||||
pr_closed:{issueCount:faker.datatype.number(100)},
|
||||
pr_merged:{issueCount:faker.datatype.number(100)},
|
||||
})
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > followup/user")
|
||||
return ({
|
||||
issues_open:{issueCount:faker.datatype.number(100)},
|
||||
issues_drafts:{issueCount:faker.datatype.number(100)},
|
||||
issues_skipped:{issueCount:faker.datatype.number(100)},
|
||||
issues_closed:{issueCount:faker.datatype.number(100)},
|
||||
pr_open:{issueCount:faker.datatype.number(100)},
|
||||
pr_drafts:{issueCount:faker.datatype.number(100)},
|
||||
pr_closed:{issueCount:faker.datatype.number(100)},
|
||||
pr_merged:{issueCount:faker.datatype.number(100)},
|
||||
})
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > gists/default")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
gists:{
|
||||
edges:[],
|
||||
nodes:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
gists:{
|
||||
edges:[
|
||||
{
|
||||
cursor:"MOCKED_CURSOR",
|
||||
},
|
||||
],
|
||||
totalCount:faker.datatype.number(100),
|
||||
nodes:[
|
||||
{
|
||||
stargazerCount:faker.datatype.number(10),
|
||||
isFork:false,
|
||||
forks:{totalCount:faker.datatype.number(10)},
|
||||
files:[{name:faker.system.fileName()}],
|
||||
comments:{totalCount:faker.datatype.number(10)},
|
||||
},
|
||||
{
|
||||
stargazerCount:faker.datatype.number(10),
|
||||
isFork:false,
|
||||
forks:{totalCount:faker.datatype.number(10)},
|
||||
files:[{name:faker.system.fileName()}],
|
||||
comments:{totalCount:faker.datatype.number(10)},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > introduction/organization")
|
||||
return ({
|
||||
organization:{
|
||||
description:faker.lorem.sentences(),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > introduction/repository")
|
||||
return ({
|
||||
repository:{
|
||||
description:faker.lorem.sentences(),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > introduction/user")
|
||||
return ({
|
||||
user:{
|
||||
bio:faker.lorem.sentences(),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > isocalendar/calendar")
|
||||
//Generate calendar
|
||||
const date = new Date(query.match(/from: "(?<date>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)"/)?.groups?.date)
|
||||
const to = new Date(query.match(/to: "(?<date>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z)"/)?.groups?.date)
|
||||
const weeks = []
|
||||
let contributionDays = []
|
||||
for (; date <= to; date.setDate(date.getDate() + 1)) {
|
||||
//Create new week on sunday
|
||||
if (date.getDay() === 0) {
|
||||
weeks.push({contributionDays})
|
||||
contributionDays = []
|
||||
}
|
||||
//Random contributions
|
||||
const contributionCount = Math.min(10, Math.max(0, faker.datatype.number(14) - 4))
|
||||
contributionDays.push({
|
||||
contributionCount,
|
||||
color:["#ebedf0", "#9be9a8", "#40c463", "#30a14e", "#216e39"][Math.ceil(contributionCount / 10 / 0.25)],
|
||||
date:date.toISOString().substring(0, 10),
|
||||
})
|
||||
}
|
||||
return ({
|
||||
user:{
|
||||
calendar:{
|
||||
contributionCalendar:{
|
||||
weeks,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > licenses/default")
|
||||
return ({
|
||||
licenses:[
|
||||
{
|
||||
spdxId:"AGPL-3.0",
|
||||
name:"GNU Affero General Public License v3.0",
|
||||
nickname:"GNU AGPLv3",
|
||||
key:"agpl-3.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"document-changes", label:"State changes"},
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"network-use-disclose", label:"Network use is distribution"},
|
||||
{key:"same-license", label:"Same license"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"Apache-2.0",
|
||||
name:"Apache License 2.0",
|
||||
nickname:null,
|
||||
key:"apache-2.0",
|
||||
limitations:[
|
||||
{key:"trademark-use", label:"Trademark use"},
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"document-changes", label:"State changes"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"BSD-2-Clause",
|
||||
name:'BSD 2-Clause "Simplified" License',
|
||||
nickname:null,
|
||||
key:"bsd-2-clause",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"BSD-3-Clause",
|
||||
name:'BSD 3-Clause "New" or "Revised" License',
|
||||
nickname:null,
|
||||
key:"bsd-3-clause",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"BSL-1.0",
|
||||
name:"Boost Software License 1.0",
|
||||
nickname:null,
|
||||
key:"bsl-1.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright--source", label:"License and copyright notice for source"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"CC0-1.0",
|
||||
name:"Creative Commons Zero v1.0 Universal",
|
||||
nickname:null,
|
||||
key:"cc0-1.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"trademark-use", label:"Trademark use"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"EPL-2.0",
|
||||
name:"Eclipse Public License 2.0",
|
||||
nickname:null,
|
||||
key:"epl-2.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"same-license", label:"Same license"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"GPL-2.0",
|
||||
name:"GNU General Public License v2.0",
|
||||
nickname:"GNU GPLv2",
|
||||
key:"gpl-2.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"document-changes", label:"State changes"},
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"same-license", label:"Same license"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"GPL-3.0",
|
||||
name:"GNU General Public License v3.0",
|
||||
nickname:"GNU GPLv3",
|
||||
key:"gpl-3.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"document-changes", label:"State changes"},
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"same-license", label:"Same license"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"LGPL-2.1",
|
||||
name:"GNU Lesser General Public License v2.1",
|
||||
nickname:"GNU LGPLv2.1",
|
||||
key:"lgpl-2.1",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"document-changes", label:"State changes"},
|
||||
{key:"same-license--library", label:"Same license (library)"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"MIT",
|
||||
name:"MIT License",
|
||||
nickname:null,
|
||||
key:"mit",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"MPL-2.0",
|
||||
name:"Mozilla Public License 2.0",
|
||||
nickname:null,
|
||||
key:"mpl-2.0",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"trademark-use", label:"Trademark use"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[
|
||||
{key:"disclose-source", label:"Disclose source"},
|
||||
{key:"include-copyright", label:"License and copyright notice"},
|
||||
{key:"same-license--file", label:"Same license (file)"},
|
||||
],
|
||||
permissions:[
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
{key:"patent-use", label:"Patent use"},
|
||||
{key:"private-use", label:"Private use"},
|
||||
],
|
||||
},
|
||||
{
|
||||
spdxId:"Unlicense",
|
||||
name:"The Unlicense",
|
||||
nickname:null,
|
||||
key:"unlicense",
|
||||
limitations:[
|
||||
{key:"liability", label:"Liability"},
|
||||
{key:"warranty", label:"Warranty"},
|
||||
],
|
||||
conditions:[],
|
||||
permissions:[
|
||||
{key:"private-use", label:"Private use"},
|
||||
{key:"commercial-use", label:"Commercial use"},
|
||||
{key:"modifications", label:"Modification"},
|
||||
{key:"distribution", label:"Distribution"},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > licenses/repository")
|
||||
return ({
|
||||
user:{
|
||||
repository:{
|
||||
licenseInfo:{spdxId:"MIT", name:"MIT License", nickname:null, key:"mit"},
|
||||
url:"https://github.com/lowlighter/metrics",
|
||||
databaseId:293860197,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > notable/contributions")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
repositoriesContributedTo:{
|
||||
edges:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
repositoriesContributedTo:{
|
||||
edges:[
|
||||
{
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
isInOrganization:true,
|
||||
owner:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
},
|
||||
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
|
||||
stargazers:{totalCount:faker.datatype.number(1000)},
|
||||
watchers:{totalCount:faker.datatype.number(1000)},
|
||||
forks:{totalCount:faker.datatype.number(1000)},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > people/default")
|
||||
const type = query.match(/(?<type>followers|following)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
[type]:{
|
||||
edges:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20 + 80 * Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
login,
|
||||
avatarUrl:null,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > people/repository")
|
||||
const type = query.match(/(?<type>stargazers|watchers)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
repository:{
|
||||
[type]:{
|
||||
edges:[],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
repository:{
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20 + 80 * Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
login,
|
||||
avatarUrl:null,
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > people/sponsors")
|
||||
const type = query.match(/(?<type>sponsorshipsAsSponsor|sponsorshipsAsMaintainer)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
login,
|
||||
[type]:{
|
||||
edges:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
login,
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20 + 80 * Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
sponsorEntity:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
},
|
||||
sponsorable:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > projects/repository")
|
||||
return ({
|
||||
user:{
|
||||
repository:{
|
||||
project:{
|
||||
name:"Repository project example",
|
||||
updatedAt:`${faker.date.recent()}`,
|
||||
body:faker.lorem.paragraph(),
|
||||
progress:{
|
||||
doneCount:faker.datatype.number(10),
|
||||
inProgressCount:faker.datatype.number(10),
|
||||
todoCount:faker.datatype.number(10),
|
||||
enabled:true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > projects/user")
|
||||
return ({
|
||||
user:{
|
||||
projects:{
|
||||
totalCount:1,
|
||||
nodes:[
|
||||
{
|
||||
name:"User-owned project",
|
||||
updatedAt:`${faker.date.recent()}`,
|
||||
body:faker.lorem.paragraph(),
|
||||
progress:{
|
||||
doneCount:faker.datatype.number(10),
|
||||
inProgressCount:faker.datatype.number(10),
|
||||
todoCount:faker.datatype.number(10),
|
||||
enabled:true,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > reactions/default")
|
||||
const type = query.match(/(?<type>issues|issueComments)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
user:{
|
||||
[type]:{
|
||||
edges:[],
|
||||
nodes:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
user:{
|
||||
[type]:{
|
||||
edges:new Array(100).fill(null).map(_ => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
createdAt:faker.date.recent(),
|
||||
reactions:{
|
||||
nodes:new Array(50).fill(null).map(_ => ({
|
||||
user:{login:faker.internet.userName()},
|
||||
content:faker.random.arrayElement(["HEART", "THUMBS_UP", "THUMBS_DOWN", "LAUGH", "CONFUSED", "EYES", "ROCKET", "HOORAY"]),
|
||||
})),
|
||||
},
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > stars/default")
|
||||
return ({
|
||||
repository:{
|
||||
createdAt: faker.date.past(),
|
||||
description:"📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !",
|
||||
forkCount:faker.datatype.number(100),
|
||||
isFork:false,
|
||||
issues:{
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
nameWithOwner:"lowlighter/metrics",
|
||||
openGraphImageUrl:"https://repository-images.githubusercontent.com/293860197/7fd72080-496d-11eb-8fe0-238b38a0746a",
|
||||
pullRequests:{
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
stargazerCount:faker.datatype.number(10000),
|
||||
licenseInfo:{
|
||||
nickname:null,
|
||||
name:"MIT License",
|
||||
},
|
||||
primaryLanguage:{
|
||||
color:"#f1e05a",
|
||||
name:"JavaScript",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > sponsors/default")
|
||||
return ({
|
||||
user:{
|
||||
sponsorsListing:{
|
||||
fullDescription:faker.lorem.sentences(),
|
||||
activeGoal:{
|
||||
percentComplete:faker.datatype.number(100),
|
||||
title:faker.lorem.sentence(),
|
||||
description:faker.lorem.sentence(),
|
||||
}
|
||||
},
|
||||
sponsorshipsAsMaintainer:{
|
||||
totalCount:faker.datatype.number(100),
|
||||
nodes:new Array(10).fill(null).map(_ => ({
|
||||
sponsorEntity:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
},
|
||||
tier:{
|
||||
monthlyPriceInDollars:faker.datatype.number(10),
|
||||
}
|
||||
}))
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > stargazers/default")
|
||||
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||
? ({
|
||||
repository:{
|
||||
stargazers:{
|
||||
edges:[],
|
||||
},
|
||||
},
|
||||
})
|
||||
: ({
|
||||
repository:{
|
||||
stargazers:{
|
||||
edges:new Array(faker.datatype.number({min:50, max:100})).fill(null).map(() => ({
|
||||
starredAt:`${faker.date.recent(30)}`,
|
||||
cursor:"MOCKED_CURSOR",
|
||||
})),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker, query, login = faker.internet.userName()}) {
|
||||
console.debug("metrics/compute/mocks > mocking graphql api result > stars/default")
|
||||
return ({
|
||||
user:{
|
||||
starredRepositories:{
|
||||
edges:[
|
||||
{
|
||||
starredAt:`${faker.date.recent(14)}`,
|
||||
node:{
|
||||
description:"📊 An image generator with 20+ metrics about your GitHub account such as activity, community, repositories, coding habits, website performances, music played, starred topics, etc. that you can put on your profile or elsewhere !",
|
||||
forkCount:faker.datatype.number(100),
|
||||
isFork:false,
|
||||
issues:{
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
nameWithOwner:"lowlighter/metrics",
|
||||
openGraphImageUrl:"https://repository-images.githubusercontent.com/293860197/7fd72080-496d-11eb-8fe0-238b38a0746a",
|
||||
pullRequests:{
|
||||
totalCount:faker.datatype.number(100),
|
||||
},
|
||||
stargazerCount:faker.datatype.number(10000),
|
||||
licenseInfo:{
|
||||
nickname:null,
|
||||
name:"MIT License",
|
||||
},
|
||||
primaryLanguage:{
|
||||
color:"#f1e05a",
|
||||
name:"JavaScript",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,341 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{username:login, page, per_page}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listEventsForAuthenticatedUser")
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/users/${login}/events?per_page=${per_page}&page=${page}`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:page < 1 ? [] : [
|
||||
{
|
||||
id:"10000000000",
|
||||
type:"CommitCommentEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
comment:{
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
path:faker.system.fileName(),
|
||||
commit_id:"MOCKED_SHA",
|
||||
body:faker.lorem.sentence(),
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000001",
|
||||
type:"PullRequestReviewCommentEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:"created",
|
||||
comment:{
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
body:faker.lorem.paragraph(),
|
||||
},
|
||||
pull_request:{
|
||||
title:faker.lorem.sentence(),
|
||||
number:1,
|
||||
user:{
|
||||
login:faker.internet.userName(),
|
||||
},
|
||||
body:"",
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000002",
|
||||
type:"IssuesEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:faker.random.arrayElement(["opened", "closed", "reopened"]),
|
||||
issue:{
|
||||
number:2,
|
||||
title:faker.lorem.sentence(),
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
body:faker.lorem.paragraph(),
|
||||
performed_via_github_app:null,
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000003",
|
||||
type:"GollumEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
pages:[
|
||||
{
|
||||
page_name:faker.lorem.sentence(),
|
||||
title:faker.lorem.sentence(),
|
||||
summary:null,
|
||||
action:"created",
|
||||
sha:"MOCKED_SHA",
|
||||
},
|
||||
],
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000004",
|
||||
type:"IssueCommentEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:"created",
|
||||
issue:{
|
||||
number:3,
|
||||
title:faker.lorem.sentence(),
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
labels:[
|
||||
{
|
||||
name:"lorem ipsum",
|
||||
color:"d876e3",
|
||||
},
|
||||
],
|
||||
state:"open",
|
||||
},
|
||||
comment:{
|
||||
body:faker.lorem.paragraph(),
|
||||
performed_via_github_app:null,
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000005",
|
||||
type:"ForkEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
forkee:{
|
||||
name:faker.random.word(),
|
||||
full_name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000006",
|
||||
type:"PullRequestReviewEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:"created",
|
||||
review:{
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
state:"approved",
|
||||
},
|
||||
pull_request:{
|
||||
state:"open",
|
||||
number:4,
|
||||
locked:false,
|
||||
title:faker.lorem.sentence(),
|
||||
user:{
|
||||
login:faker.internet.userName(),
|
||||
},
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000007",
|
||||
type:"ReleaseEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:"published",
|
||||
release:{
|
||||
tag_name:`v${faker.datatype.number()}.${faker.datatype.number()}`,
|
||||
name:faker.random.words(4),
|
||||
draft:faker.datatype.boolean(),
|
||||
prerelease:faker.datatype.boolean(),
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000008",
|
||||
type:"CreateEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
ref:faker.lorem.slug(),
|
||||
ref_type:faker.random.arrayElement(["tag", "branch"]),
|
||||
master_branch:"master",
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"100000000009",
|
||||
type:"WatchEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:"lowlighter/metrics",
|
||||
},
|
||||
payload:{action:"started"},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000010",
|
||||
type:"DeleteEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
ref:faker.lorem.slug(),
|
||||
ref_type:faker.random.arrayElement(["tag", "branch"]),
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000011",
|
||||
type:"PushEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
size:1,
|
||||
ref:"refs/heads/master",
|
||||
commits:[
|
||||
{
|
||||
sha:"MOCKED_SHA",
|
||||
message:faker.lorem.sentence(),
|
||||
url:"https://api.github.com/repos/lowlighter/metrics/commits/MOCKED_SHA",
|
||||
},
|
||||
],
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000012",
|
||||
type:"PullRequestEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
action:faker.random.arrayElement(["opened", "closed"]),
|
||||
number:5,
|
||||
pull_request:{
|
||||
user:{
|
||||
login,
|
||||
},
|
||||
state:"open",
|
||||
title:faker.lorem.sentence(),
|
||||
additions:faker.datatype.number(1000),
|
||||
deletions:faker.datatype.number(1000),
|
||||
changed_files:faker.datatype.number(10),
|
||||
},
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000013",
|
||||
type:"MemberEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{
|
||||
member:{
|
||||
login:faker.internet.userName(),
|
||||
},
|
||||
action:"added",
|
||||
},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
{
|
||||
id:"10000000014",
|
||||
type:"PublicEvent",
|
||||
actor:{
|
||||
login,
|
||||
},
|
||||
repo:{
|
||||
name:`${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
payload:{},
|
||||
created_at:faker.date.recent(7),
|
||||
public:true,
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
//Imports
|
||||
import listEventsForAuthenticatedUser from "./listEventsForAuthenticatedUser.mjs"
|
||||
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{username:login, page, per_page}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.activity.listRepoEvents")
|
||||
return listEventsForAuthenticatedUser(...arguments)
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, args) {
|
||||
return ({
|
||||
status:200,
|
||||
url:"https://api.github.com/rate_limit",
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:{
|
||||
resources:{
|
||||
core:{limit:5000, used:0, remaining:5000, reset:0},
|
||||
search:{limit:30, used:0, remaining:30, reset:0},
|
||||
graphql:{limit:5000, used:0, remaining:5000, reset:0},
|
||||
integration_manifest:{limit:5000, used:0, remaining:5000, reset:0},
|
||||
source_import:{limit:100, used:0, remaining:100, reset:0},
|
||||
code_scanning_upload:{limit:500, used:0, remaining:500, reset:0},
|
||||
},
|
||||
rate:{limit:5000, used:0, remaining:"MOCKED", reset:0},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{owner, repo}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getContributorsStats")
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/repos/${owner}/${repo}/stats/contributors`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:[
|
||||
{
|
||||
total:faker.datatype.number(10000),
|
||||
weeks:[
|
||||
{w:1, a:faker.datatype.number(10000), d:faker.datatype.number(10000), c:faker.datatype.number(10000)},
|
||||
{w:2, a:faker.datatype.number(10000), d:faker.datatype.number(10000), c:faker.datatype.number(10000)},
|
||||
{w:3, a:faker.datatype.number(10000), d:faker.datatype.number(10000), c:faker.datatype.number(10000)},
|
||||
{w:4, a:faker.datatype.number(10000), d:faker.datatype.number(10000), c:faker.datatype.number(10000)},
|
||||
],
|
||||
author:{
|
||||
login:owner,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{owner, repo}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getViews")
|
||||
const count = faker.datatype.number(10000) * 2
|
||||
const uniques = faker.datatype.number(count) * 2
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/repos/${owner}/${repo}/traffic/views`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:{
|
||||
count,
|
||||
uniques,
|
||||
views:[
|
||||
{timestamp:`${faker.date.recent()}`, count:count / 2, uniques:uniques / 2},
|
||||
{timestamp:`${faker.date.recent()}`, count:count / 2, uniques:uniques / 2},
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{page, per_page, owner, repo}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listCommits")
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/repos/${owner}/${repo}/commits?per_page=${per_page}&page=${page}`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:page < 2
|
||||
? new Array(per_page).fill(null).map(() => ({
|
||||
sha:"MOCKED_SHA",
|
||||
get author() {
|
||||
return this.commit.author
|
||||
},
|
||||
commit:{
|
||||
message:faker.lorem.sentence(),
|
||||
author:{
|
||||
name:owner,
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
date:`${faker.date.recent(14)}`,
|
||||
},
|
||||
committer:{
|
||||
name:owner,
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
date:`${faker.date.recent(14)}`,
|
||||
},
|
||||
},
|
||||
}))
|
||||
: [],
|
||||
})
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{owner, repo}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.listContributors")
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/repos/${owner}/${repo}/contributors`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:new Array(40 + faker.datatype.number(60)).fill(null).map(() => ({
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
contributions:faker.datatype.number(1000),
|
||||
})),
|
||||
})
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, args) {
|
||||
//Arguments
|
||||
const [url] = args
|
||||
//Head request
|
||||
if (/^HEAD .$/.test(url)) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.request HEAD")
|
||||
return ({
|
||||
status:200,
|
||||
url:"https://api.github.com/",
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:undefined,
|
||||
})
|
||||
}
|
||||
//Commit content
|
||||
if (/^https:..api.github.com.repos.lowlighter.metrics.commits.MOCKED_SHA/.test(url)) {
|
||||
console.debug(`metrics/compute/mocks > mocking rest api result > rest.request ${url}`)
|
||||
return ({
|
||||
status:200,
|
||||
url:"https://api.github.com/repos/lowlighter/metrics/commits/MOCKED_SHA",
|
||||
data:{
|
||||
sha:"MOCKED_SHA",
|
||||
commit:{
|
||||
author:{
|
||||
name:faker.internet.userName(),
|
||||
email:faker.internet.email(),
|
||||
date:`${faker.date.recent(7)}`,
|
||||
},
|
||||
committer:{
|
||||
name:faker.internet.userName(),
|
||||
email:faker.internet.email(),
|
||||
date:`${faker.date.recent(7)}`,
|
||||
},
|
||||
url:"https://api.github.com/repos/lowlighter/metrics/commits/MOCKED_SHA",
|
||||
},
|
||||
author:{
|
||||
login:faker.internet.userName(),
|
||||
id:faker.datatype.number(100000000),
|
||||
},
|
||||
committer:{
|
||||
login:faker.internet.userName(),
|
||||
id:faker.datatype.number(100000000),
|
||||
},
|
||||
files:[
|
||||
{
|
||||
sha:"MOCKED_SHA",
|
||||
filename:faker.system.fileName(),
|
||||
patch:'@@ -0,0 +1,5 @@\n+//Imports\n+ import app from "./src/app.mjs"\n+\n+//Start app\n+ await app()\n\\ No newline at end of file',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return target(...args)
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/**Mocked data */
|
||||
export default function({faker}, target, that, [{username}]) {
|
||||
console.debug("metrics/compute/mocks > mocking rest api result > rest.repos.getByUsername")
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/users/${username}/`,
|
||||
headers:{
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:{
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
contributions:faker.datatype.number(1000),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
//Imports
|
||||
import fs from "fs/promises"
|
||||
import axios from "axios"
|
||||
import faker from "faker"
|
||||
import paths from "path"
|
||||
import rss from "rss-parser"
|
||||
import urls from "url"
|
||||
|
||||
//Mocked state
|
||||
let mocked = false
|
||||
|
||||
//Mocking
|
||||
export default async function({graphql, rest}) {
|
||||
//Check if already mocked
|
||||
if (mocked)
|
||||
return {graphql, rest}
|
||||
mocked = true
|
||||
console.debug("metrics/compute/mocks > mocking")
|
||||
|
||||
//Load mocks
|
||||
const __mocks = paths.join(paths.dirname(urls.fileURLToPath(import.meta.url)))
|
||||
const mock = async ({directory, mocks}) => {
|
||||
for (const entry of await fs.readdir(directory)) {
|
||||
if ((await fs.lstat(paths.join(directory, entry))).isDirectory()) {
|
||||
if (!mocks[entry])
|
||||
mocks[entry] = {}
|
||||
await mock({directory:paths.join(directory, entry), mocks:mocks[entry]})
|
||||
}
|
||||
else
|
||||
mocks[entry.replace(/[.]mjs$/, "")] = (await import(urls.pathToFileURL(paths.join(directory, entry)).href)).default
|
||||
|
||||
}
|
||||
return mocks
|
||||
}
|
||||
const mocks = await mock({directory:paths.join(__mocks, "api"), mocks:{}})
|
||||
|
||||
//GraphQL API mocking
|
||||
{
|
||||
//Unmocked
|
||||
console.debug("metrics/compute/mocks > mocking graphql api")
|
||||
const unmocked = graphql
|
||||
//Mocked
|
||||
graphql = new Proxy(unmocked, {
|
||||
apply(target, that, args) {
|
||||
//Arguments
|
||||
const [query] = args
|
||||
const login = query.match(/login: "(?<login>.*?)"/)?.groups?.login ?? faker.internet.userName()
|
||||
|
||||
//Search for mocked query
|
||||
for (const mocked of Object.keys(mocks.github.graphql)) {
|
||||
if (new RegExp(`^query ${mocked.replace(/([.]\w)/g, (_, g) => g.toLocaleUpperCase().substring(1)).replace(/^(\w)/g, (_, g) => g.toLocaleUpperCase())} `).test(query))
|
||||
return mocks.github.graphql[mocked]({faker, query, login})
|
||||
}
|
||||
|
||||
//Unmocked call
|
||||
return target(...args)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//Rest API mocking
|
||||
{
|
||||
//Unmocked
|
||||
console.debug("metrics/compute/mocks > mocking rest api")
|
||||
const unmocked = {}
|
||||
//Mocked
|
||||
const mocker = ({path = "rest", mocks, mocked}) => {
|
||||
for (const [key, value] of Object.entries(mocks)) {
|
||||
console.debug(`metrics/compute/mocks > mocking rest api > mocking ${path}.${key}`)
|
||||
if (typeof value === "function") {
|
||||
unmocked[path] = value
|
||||
mocked[key] = new Proxy(unmocked[path], {apply:value.bind(null, {faker})})
|
||||
}
|
||||
else
|
||||
mocker({path:`${path}.${key}`, mocks:mocks[key], mocked:mocked[key]})
|
||||
|
||||
}
|
||||
}
|
||||
mocker({mocks:mocks.github.rest, mocked:rest})
|
||||
}
|
||||
|
||||
//Axios mocking
|
||||
{
|
||||
//Unmocked
|
||||
console.debug("metrics/compute/mocks > mocking axios")
|
||||
const unmocked = {get:axios.get, post:axios.post}
|
||||
|
||||
//Mocked post requests
|
||||
axios.post = new Proxy(unmocked.post, {
|
||||
apply(target, that, args) {
|
||||
//Arguments
|
||||
const [url, body] = args
|
||||
|
||||
//Search for mocked request
|
||||
for (const service of Object.keys(mocks.axios.post)) {
|
||||
const mocked = mocks.axios.post[service]({faker, url, body})
|
||||
if (mocked)
|
||||
return mocked
|
||||
}
|
||||
|
||||
//Unmocked call
|
||||
return target(...args)
|
||||
},
|
||||
})
|
||||
|
||||
//Mocked get requests
|
||||
axios.get = new Proxy(unmocked.get, {
|
||||
apply(target, that, args) {
|
||||
//Arguments
|
||||
const [url, options] = args
|
||||
|
||||
//Search for mocked request
|
||||
for (const service of Object.keys(mocks.axios.get)) {
|
||||
const mocked = mocks.axios.get[service]({faker, url, options})
|
||||
if (mocked)
|
||||
return mocked
|
||||
}
|
||||
|
||||
//Unmocked call
|
||||
return target(...args)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//RSS mocking
|
||||
{
|
||||
//Unmocked
|
||||
console.debug("metrics/compute/mocks > mocking rss-parser")
|
||||
|
||||
//Mock rss feed
|
||||
rss.prototype.parseURL = function(url) {
|
||||
console.debug(`metrics/compute/mocks > mocking rss feed result > ${url}`)
|
||||
return ({
|
||||
items:new Array(30).fill(null).map(_ => ({
|
||||
title:faker.lorem.sentence(),
|
||||
link:faker.internet.url(),
|
||||
content:faker.lorem.paragraphs(),
|
||||
contentSnippet:faker.lorem.paragraph(),
|
||||
isoDate:faker.date.recent(),
|
||||
})),
|
||||
title:faker.lorem.words(),
|
||||
description:faker.lorem.paragraph(),
|
||||
link:url,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//Return mocked elements
|
||||
return {graphql, rest}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import cache from "memory-cache"
|
||||
import util from "util"
|
||||
import metrics from "../metrics/index.mjs"
|
||||
import setup from "../metrics/setup.mjs"
|
||||
import mocks from "../mocks/index.mjs"
|
||||
import mocks from "../../../tests/mocks/index.mjs"
|
||||
|
||||
/**App */
|
||||
export default async function({mock, nosettings} = {}) {
|
||||
|
||||
Reference in New Issue
Block a user