-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Tests #106
Merged
Merged
Fix Tests #106
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3b4609b
feat: add tests for valid docs and badDocName
247ae91
feat: added test for deep comparison of fields of doc with decodedDoc
5aa150a
feat: fix tests for nested objects (one-level) and floats
1358a69
chore: refactor ifelse to switch
a0db8e2
feat: fix bug in `encode-convertions/convertProject`, refactor tests
e459b99
feat: observation.proto/{lat,lon}: use double instead of float
c075ec0
add fields with default value to `field` to pass deepEqual test
e98e928
feat: add tests for optional values, proto and schema changes
fc139a4
feat: add configStore tests with additional fields
ef595e1
Merge branch 'master' of github.com:digidem/mapeo-schema into feat/fi…
5f12072
feat: fix test after master merge
be09f67
feat: add tests for extra non required values, and cleanup
e9097d8
feat: fix buf in encoding field tags
9e3aca1
chore: format with prettier
gmaclennan f2dff2e
remove unused import
gmaclennan fa016ac
Make badDocs test more DRY
gmaclennan 0ded478
remove unused file
gmaclennan d8b508d
move fixtures into separate files
gmaclennan 756d345
fix typos and make goodDocs correct types
gmaclennan a1793dc
fix typo acurracy -> accuracy
gmaclennan 2838ad7
remove extra fields fixtures - not necessary
gmaclennan 8a6113d
remove doesNotThrow check
gmaclennan d7fd299
only define fields that are expected to change
gmaclennan 17706d2
let -> const
gmaclennan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { randomBytes } from 'node:crypto' | ||
|
||
export const fixtures = { | ||
onlyId: { | ||
text: 'test encoding of record with missing fields', | ||
plan: 1, | ||
doc: {id: randomBytes(32).toString('hex')} | ||
}, | ||
badDocName: { | ||
text: 'test encoding of wrong record type', | ||
plan: 1, | ||
doc: { | ||
gmaclennan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id: randomBytes(32).toString('hex'), | ||
schemaName: 'doesnotexist', | ||
links: [], | ||
createdAt: new Date().toJSON(), | ||
refs: [], | ||
attachments: [], | ||
metadata: { | ||
manual_location: true, | ||
}, | ||
} | ||
}, | ||
goodDocs:{ | ||
text: 'test encoding of rightfully formated records', | ||
plan: 1, | ||
docs: { | ||
observation:{ | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'observation', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
lat: 10, | ||
lon: -20.3, | ||
refs: [], | ||
attachments: [], | ||
metadata: { | ||
manualLocation: true, | ||
}, | ||
tags: {} | ||
}, | ||
project: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'project', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
name: 'myProject', | ||
defaultPresets: { | ||
point: ["myPointPreset"], | ||
vertex: ["myVertexPreset"], | ||
area: ["myAreaPreset"], | ||
line: ["myLinePreset"], | ||
relation: ["myRelationPreset"], | ||
} | ||
}, | ||
field: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'field', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
tagKey: "myTagKey", | ||
type: "text", | ||
label: "myLabel" | ||
}, | ||
preset: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'preset', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
name:"myPreset", | ||
geometry:["point"], | ||
tags:{}, | ||
addTags:{}, | ||
removeTags:{}, | ||
fieldIds:[], | ||
terms:[] | ||
}, | ||
role: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'role', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
role:"author", | ||
projectId:randomBytes(32).toString('hex'), | ||
action:"role_set", | ||
signature:"signature", | ||
authorIndex:2, | ||
deviceIndex:4, | ||
authorId:randomBytes(32).toString('hex'), | ||
capabilityType:"capability" | ||
}, | ||
device: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'device', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
action:"ban", | ||
authorId:randomBytes(32).toString('hex'), | ||
projectId:randomBytes(32).toString('hex'), | ||
signature:"mySignature", | ||
authorIndex:2, | ||
deviceIndex:20, | ||
capabilityType:"someCapability", | ||
}, | ||
coreOwnership: { | ||
docId: randomBytes(32).toString('hex'), | ||
versionId: `${randomBytes(32).toString('hex')}/0`, | ||
schemaName: 'coreOwnership', | ||
createdAt: new Date().toJSON(), | ||
updatedAt: new Date().toJSON(), | ||
links: [], | ||
action:"remove", | ||
coreId:randomBytes(32).toString('hex'), | ||
projectId:randomBytes(32).toString('hex'), | ||
storeType:"blob", | ||
signature:"mySig", | ||
authorIndex: 10, | ||
deviceIndex: 9, | ||
authorId:randomBytes(32).toString('hex'), | ||
capabilityType: "someCapability" | ||
} | ||
} | ||
} | ||
} |
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,88 +1,103 @@ | ||
import test from 'tape' | ||
import { encode, decode, validate } from '../index.js' | ||
import { randomBytes } from 'node:crypto' | ||
import { docs } from './docs.js' | ||
import { fixtures } from './fixture.js' | ||
import { encode } from '../dist/encode.js' | ||
import { decode } from '../dist/decode.js' | ||
import { validate } from '../dist/validate.js' | ||
import { parseVersionId } from '../dist/lib/utils.js' | ||
// import { randomBytes } from 'node:crypto' | ||
|
||
test('test encoding of record with missing fields', async (t) => { | ||
t.plan(1) | ||
t.throws(() => { | ||
encode(docs.onlyId) | ||
}) | ||
}) | ||
|
||
test('test encoding of wrong record type', async (t) => { | ||
t.plan(1) | ||
t.throws(() => { | ||
encode(docs.badDocType) | ||
}) | ||
}) | ||
|
||
test('test encoding of record with wrong schema version', async (t) => { | ||
t.plan(1) | ||
t.throws(() => { | ||
encode(docs.badSchemaVersion) | ||
{ | ||
const {text,plan,doc} = fixtures.onlyId | ||
test(text, async(t) => { | ||
t.plan(plan) | ||
t.throws(() => { | ||
encode(doc) | ||
}) | ||
}) | ||
}) | ||
|
||
test('test encoding of rightfully formated record', async (t) => { | ||
const goodDocs = Object.keys(docs.good) | ||
t.plan(goodDocs.length) | ||
goodDocs.forEach((k) => { | ||
const doc = docs.good[k] | ||
t.doesNotThrow(() => { | ||
} | ||
{ | ||
const {text,plan, doc} = fixtures.badDocName | ||
test(text,async(t) => { | ||
t.plan(plan) | ||
t.throws(() => { | ||
encode(doc) | ||
}, `testing ${k}`) | ||
}) | ||
}) | ||
}) | ||
|
||
test('test validation of record', async (t) => { | ||
const goodDocs = Object.keys(docs.good) | ||
t.plan(goodDocs.length) | ||
goodDocs.forEach((k) => { | ||
const doc = docs.good[k] | ||
const record = decode(encode(doc), { | ||
coreKey: randomBytes(32), | ||
index: 0, | ||
} | ||
{ | ||
const {text,docs} = fixtures.goodDocs | ||
test({text},async(t) => { | ||
t.plan(Object.keys(docs).length) | ||
Object.keys(docs).forEach((docName) => { | ||
const doc = docs[docName] | ||
t.doesNotThrow(() => { | ||
const buf = encode(doc) | ||
console.log(decode(buf, parseVersionId(doc.versionId))) | ||
}, `testing ${docName}`) | ||
}) | ||
t.doesNotThrow(() => { | ||
// field has a type which is different from the rest :| | ||
if (k !== 'field') validate(record) | ||
}, `testing validation of ${k}`) | ||
}) | ||
}) | ||
|
||
test('test encoding, decoding of record and comparing the two versions', async (t) => { | ||
const goodDocs = Object.keys(docs.good) | ||
goodDocs.forEach((k) => { | ||
const doc = docs.good[k] | ||
const record = decode(encode(doc), { | ||
coreKey: randomBytes(32), | ||
index: 0, | ||
}) | ||
const fields = Object.keys(doc) | ||
// t.plan(goodDocs.length * fields.length * 2) | ||
fields.forEach((f) => { | ||
console.log(typeof record[f], typeof doc[f]) | ||
const msg = `checking ${f} for ${k}` | ||
record[f] && doc[f] ? t.pass(msg) : t.fail(msg) | ||
} | ||
|
||
// if field is not an object, check equality | ||
// since objects as fields usually mean the possibility of additionalFields in jsonSchemas | ||
if (typeof record[f] !== 'object') { | ||
t.equal(record[f], doc[f], `comparing value of ${f} for ${k}`) | ||
} | ||
}) | ||
}) | ||
}) | ||
// test('test encoding of rightfully formated record', async (t) => { | ||
// const goodDocs = Object.keys(docs.good) | ||
// t.plan(goodDocs.length) | ||
// goodDocs.forEach((k) => { | ||
// const doc = docs.good[k] | ||
// t.doesNotThrow(() => { | ||
// encode(doc) | ||
// }, `testing ${k}`) | ||
// }) | ||
// }) | ||
|
||
test('test decoding of record without passing core key and index', async (t) => { | ||
const goodDocs = Object.keys(docs.good) | ||
t.plan(goodDocs.length) | ||
goodDocs.forEach((key) => { | ||
const doc = docs.good[key] | ||
const record = encode(doc) | ||
t.throws(() => { | ||
decode(record) | ||
}, `testing ${key}`) | ||
}) | ||
}) | ||
// test('test validation of record', async (t) => { | ||
// const goodDocs = Object.keys(docs.good) | ||
// t.plan(goodDocs.length) | ||
// goodDocs.forEach((k) => { | ||
// const doc = docs.good[k] | ||
// const record = decode(encode(doc), { | ||
// coreKey: randomBytes(32), | ||
// index: 0, | ||
// }) | ||
// t.doesNotThrow(() => { | ||
// // field has a type which is different from the rest :| | ||
// if (k !== 'field') validate(record) | ||
// }, `testing validation of ${k}`) | ||
// }) | ||
// }) | ||
|
||
// test('test encoding, decoding of record and comparing the two versions', async (t) => { | ||
// const goodDocs = Object.keys(docs.good) | ||
// goodDocs.forEach((k) => { | ||
// const doc = docs.good[k] | ||
// const record = decode(encode(doc), { | ||
// coreKey: randomBytes(32), | ||
// index: 0, | ||
// }) | ||
// const fields = Object.keys(doc) | ||
// // t.plan(goodDocs.length * fields.length * 2) | ||
// fields.forEach((f) => { | ||
// console.log(typeof record[f], typeof doc[f]) | ||
// const msg = `checking ${f} for ${k}` | ||
// record[f] && doc[f] ? t.pass(msg) : t.fail(msg) | ||
|
||
// // if field is not an object, check equality | ||
// // since objects as fields usually mean the possibility of additionalFields in jsonSchemas | ||
// if (typeof record[f] !== 'object') { | ||
// t.equal(record[f], doc[f], `comparing value of ${f} for ${k}`) | ||
// } | ||
// }) | ||
// }) | ||
// }) | ||
|
||
// test('test decoding of record without passing core key and index', async (t) => { | ||
// const goodDocs = Object.keys(docs.good) | ||
// t.plan(goodDocs.length) | ||
// goodDocs.forEach((key) => { | ||
// const doc = docs.good[key] | ||
// const record = encode(doc) | ||
// t.throws(() => { | ||
// decode(record) | ||
// }, `testing ${key}`) | ||
// }) | ||
// }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe change to
docId
, since testing missing fields not invalid fields.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that field was copy/pasted from older tests, I should change that.