Completed
Push — master ( 90f2e7...43ea68 )
by Barry
23s
created

te local schema should failꞌ)   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
c 1
b 0
f 1
nc 4
nop 0
dl 0
loc 22
rs 9.2
1
/* global describe, it */
2
const assert = require('chai').assert
3
const skApi = require('../dist/index.js')
4
const fs = require('fs-extra')
5
6
describe('Schema loading', function () {
7
  // on entering this test there may or may not be schemas already cached
8
  // so we will load, unload, try to load known bad, unload and load
9
  it('schemas loaded without errors', function () {
10
    skApi.loadSchemasSync()
11
    assert(skApi.getSchemas().status === 'loaded')
12
  })
13
14
  it('schemas unloaded without errors', function () {
15
    skApi.unloadSchemasSync()
16
    assert(Object.keys(skApi.getSchemas()).length === 0)
17
  })
18
19
  it('loading incomplete local schema should fail', function () {
20
    var moved = false
21
    var schemaLoc = './schemas'
22
    // first check if we have a schemas folder present. If so move it away.
23
    if (fs.existsSync(schemaLoc)) {
24
      fs.moveSync(schemaLoc, schemaLoc + '_copy', true) // overwrites anythins in 'schemas_copy' if present
25
      moved = true
26
    }
27
    // create a dummy signalk.json file in schemas to fool the loader in to trying to load schemas locally
28
    fs.outputJSONSync(schemaLoc + '/signalk.json', {'test': 'test'})
29
    // run the test
30
    var result = !skApi.loadSchemasSync() // we're not expecting it to load
31
    // remove the Schema directory and reinstate the old one if applicable
32
    fs.removeSync(schemaLoc + '/signalk.json')
33
    if (moved) {
34
      // return the schemas folder to how it was
35
      fs.moveSync(schemaLoc + '_copy', schemaLoc, true) // overwrites schemas used for the test
36
    } else {
37
      fs.removeSync(schemaLoc)
38
    }
39
    assert(result)
40
  })
41
42
  it('schemas unloaded without errors (2)', function () {
43
    skApi.unloadSchemasSync()
44
    assert(Object.keys(skApi.getSchemas()).length === 0)
45
  })
46
47
  it('schemas loaded without errors (2)', function () {
48
    skApi.loadSchemasSync()
49
    assert(skApi.getSchemas().status === 'loaded')
50
  })
51
})
52