-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor mock api server to fail on error
- Loading branch information
Showing
2 changed files
with
42 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,51 @@ | ||
var http = require('http'); | ||
const wbEdit = require( 'wikibase-edit' )( require( './wikibase-edit.config' ) ); | ||
|
||
var x = 0 | ||
http.createServer(async function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'text/json'}); | ||
http.createServer(function (req, res) { | ||
(async () => { | ||
switch (req.url) { | ||
case '/getBatches': | ||
const numEntities = 20; | ||
const entities = []; | ||
|
||
numEntities = 20; | ||
entities = []; | ||
for (let i = 1; i <= numEntities; ++i) { | ||
const { entity } = await wbEdit.entity.create({ | ||
type: 'item', | ||
labels: { | ||
'en': new Date().toISOString() | ||
}, | ||
descriptions: { | ||
'en': new Date().toDateString() + new Date().toISOString() | ||
} | ||
}); | ||
|
||
for(var i=1; i <= numEntities; ++i){ | ||
const { entity } = await wbEdit.entity.create({ | ||
type: 'item', | ||
labels: { | ||
'en': new Date().toISOString() | ||
}, | ||
descriptions: { | ||
'en': new Date().toDateString() + new Date().toISOString() | ||
console.log('created item id', entity.id) | ||
entities.push(entity.id) | ||
} | ||
}); | ||
|
||
console.log('created item id', entity.id) | ||
entities.push(entity.id) | ||
} | ||
console.log(new Date().toISOString()); | ||
|
||
x += numEntities; | ||
console.log(new Date().toISOString()); | ||
responseObject = { | ||
'entityIds': entities.join(','), | ||
'wiki': { | ||
'domain': process.env.API_WIKIBASE_DOMAIN, | ||
'wiki_queryservice_namespace': { | ||
'backend': process.env.API_WDQS_BACKEND, | ||
'namespace': 'wdq' | ||
} | ||
}, | ||
|
||
responseObject = { | ||
'entityIds': entities.join(','), | ||
'wiki': { | ||
'domain': process.env.API_WIKIBASE_DOMAIN, | ||
'wiki_queryservice_namespace': { | ||
'backend': process.env.API_WDQS_BACKEND, | ||
'namespace': 'wdq' | ||
} | ||
}, | ||
|
||
}; | ||
res.end(JSON.stringify([responseObject])); | ||
}; | ||
res.writeHead(200, {'Content-Type': 'text/json'}); | ||
res.end(JSON.stringify([responseObject])); | ||
default: | ||
res.writeHead(404); | ||
res.end('Not found'); | ||
} | ||
})() | ||
.catch((err) => { | ||
console.error('Failed handling request: %s', err.message); | ||
res.writeHead(500); | ||
res.end(err.message); | ||
}) | ||
}).listen(3030); |