@bonniernews/fake-tool-api
Advanced tools
Comparing version 1.0.11 to 1.1.0
20
index.js
@@ -14,2 +14,3 @@ import nock from "nock"; | ||
const singleContentRegex = /^\/([\w-]+)\/([\w-]+)$/; | ||
const workingCopyRegex = /^\/([\w-]+)\/([\w-]+)\/working-copy$/; | ||
const putContentRegex = /^\/([\w-]+)\/([\w-]+)\??([^&]*)$/; | ||
@@ -68,2 +69,4 @@ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89abcd][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
.reply(interceptable(getContent)) | ||
.get(workingCopyRegex) | ||
.reply(interceptable(getWorkingCopy)) | ||
.put(putContentRegex) | ||
@@ -85,4 +88,6 @@ .reply(interceptable(putContent)) | ||
// resets content an initialize basic types () | ||
let workingCopiesByType = {}; | ||
export function resetContent() { | ||
initBasetypes(); | ||
workingCopiesByType = {}; | ||
slugs = []; | ||
@@ -101,2 +106,10 @@ interceptor = () => { }; | ||
export function addWorkingCopy(type, id, content) { | ||
if (!workingCopiesByType[type]) { | ||
workingCopiesByType[type] = {}; | ||
} | ||
workingCopiesByType[type][id] = { created: new Date().toISOString(), updated: new Date().toISOString(), ...content }; | ||
} | ||
export async function addContent(type, id, content, skipEvents) { | ||
@@ -464,2 +477,9 @@ if (!contentByType[type]) { | ||
function getWorkingCopy(url) { | ||
const matches = url.match(workingCopyRegex); | ||
const [ , type, id ] = matches || []; | ||
const workingCopy = workingCopiesByType[type]?.[id]; | ||
return workingCopy ? [ 200, workingCopy ] : [ 404 ]; | ||
} | ||
function getContent(url) { | ||
@@ -466,0 +486,0 @@ const matches = url.match(singleContentRegex); |
{ | ||
"name": "@bonniernews/fake-tool-api", | ||
"version": "1.0.11", | ||
"version": "1.1.0", | ||
"type": "module", | ||
@@ -29,2 +29,2 @@ "description": "Mocked Bonnier News tool api, for use in automated tests", | ||
} | ||
} | ||
} |
22636
700