@bonniernews/fake-tool-api
Advanced tools
Comparing version 1.0.0 to 1.0.1
37
index.js
@@ -72,2 +72,5 @@ import nock from "nock"; | ||
.persist() | ||
.post("/search") | ||
.reply(interceptable(search)) | ||
.persist() | ||
.get("/types") | ||
@@ -100,3 +103,3 @@ .reply(interceptable(getTypes)) | ||
} | ||
contentByType[type][id] = { updated: new Date().toISOString(), ...content, sequenceNumber: 1 }; | ||
contentByType[type][id] = { created: new Date().toISOString(), updated: new Date().toISOString(), ...content, sequenceNumber: 1 }; | ||
if (types[type]?.versioned) { | ||
@@ -490,2 +493,32 @@ storeVersion(type, id, { ...contentByType[type][id], updated: new Date().toISOString() }); | ||
function search(url, body) { | ||
let matchingContent = Object.keys(contentByType).flatMap((typeName) => { | ||
const ofType = contentByType[typeName]; | ||
const ids = Object.keys(ofType); | ||
return ids.map((id) => { | ||
const content = ofType[id]; | ||
const hit = { | ||
type: typeName, | ||
id, | ||
title: content.attributes?.name, | ||
}; | ||
if (body.returnContent) { | ||
hit.content = content; | ||
} | ||
return hit; | ||
}); | ||
}); | ||
if (body.q) { | ||
matchingContent = matchingContent.filter((potentialHit) => { | ||
const titleTokens = (potentialHit.title || "").split(" ").map((t) => t.toLowerCase()); | ||
return titleTokens.includes(body.q.toLocaleLowerCase()); | ||
}); | ||
} | ||
return [ 200, { hits: matchingContent, total: matchingContent.length } ]; | ||
} | ||
function getTypes() { | ||
@@ -508,3 +541,3 @@ return [ 200, Object.values(types) ]; | ||
name: "article", | ||
properties: { attributes: { type: "object", properties: { headline: { type: "string" } } } }, | ||
properties: { attributes: { type: "object", properties: { name: { type: "string" }, headline: { type: "string" } } } }, | ||
}); | ||
@@ -511,0 +544,0 @@ } |
{ | ||
"name": "@bonniernews/fake-tool-api", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Mocked Bonnier News tool api, for use in automated tests", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19173
599