Browse Source

export command as namespace on type

Kieran Gibb 2 years ago
parent
commit
c37547aec6
No known key found for this signature in database
3 changed files with 6 additions and 23 deletions
  1. 2
    10
      schemas/commands/broadcast/start.js
  2. 2
    10
      schemas/commands/broadcast/stop.js
  3. 2
    3
      test/index.test.js

+ 2
- 10
schemas/commands/broadcast/start.js View File

@@ -1,19 +1,11 @@
1 1
 var baseSchema = require('../../schema')
2 2
 
3 3
 module.exports = Object.assign({}, baseSchema, {
4
-  required: [...baseSchema.required, 'content'],
4
+  required: [...baseSchema.required],
5 5
   properties: {
6 6
     type: {
7 7
       type: 'string',
8
-      pattern: '^broadcast'
9
-    },
10
-    content: {
11
-      type: 'object',
12
-      required: ['command'],
13
-      command: {
14
-        type: 'string',
15
-        pattern: '^start$'
16
-      }
8
+      pattern: '^broadcast/start'
17 9
     }
18 10
   }
19 11
 })

+ 2
- 10
schemas/commands/broadcast/stop.js View File

@@ -1,19 +1,11 @@
1 1
 var baseSchema = require('../../schema')
2 2
 
3 3
 module.exports = Object.assign({}, baseSchema, {
4
-  required: [...baseSchema.required, 'content'],
4
+  required: [...baseSchema.required],
5 5
   properties: {
6 6
     type: {
7 7
       type: 'string',
8
-      pattern: '^broadcast'
9
-    },
10
-    content: {
11
-      type: 'object',
12
-      required: ['command'],
13
-      command: {
14
-        type: 'string',
15
-        pattern: '^stop$'
16
-      }
8
+      pattern: '^broadcast/stop'
17 9
     }
18 10
   }
19 11
 })

+ 2
- 3
test/index.test.js View File

@@ -8,8 +8,7 @@ describe('broadcast', (context) => {
8 8
   context('valid', async (assert, next) => {
9 9
     var data = {
10 10
       timestamp: Date.now(),
11
-      type: "broadcast",
12
-      content: { command: "start" }
11
+      type: "broadcast/start",
13 12
     }
14 13
 
15 14
     var isValid = schemas.commands.broadcast.start(data)
@@ -20,7 +19,7 @@ describe('broadcast', (context) => {
20 19
   context('invalid', async (assert, next) => {
21 20
     var data = {
22 21
       timestamp: Date.now(),
23
-      type: "broadcast"
22
+      type: "broadcast/stop"
24 23
     }
25 24
 
26 25
     var isValid = schemas.commands.broadcast.start(data)