Skip to content

Commit

Permalink
Merge pull request #7 from akdilsiz/development
Browse files Browse the repository at this point in the history
 Fix: to object logic
  • Loading branch information
akdilsiz committed Sep 30, 2023
2 parents 9ad1b2d + 64c4da5 commit 1debd29
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
23 changes: 16 additions & 7 deletions eventTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ class EventTransaction {
}
Encode() {
try {
if (!(this.Meta instanceof MetaData)) {
return { encoded: null, error: ErrArguments }
}

return {
encoded: encode({
Name: this.Name,
Type: this.Type,
UUID: this.UUID,
ParentUUID: this.ParentUUID,
Meta: this.Meta.ToObject()
Meta: {
IsDir: this.Meta.IsDir,
Sum: this.Meta.Sum,
Size: this.Meta.Size,
CreatedAt: this.Meta.CreatedAt,
Permission: this.Meta.Permission
}
}),
error: null
}
Expand All @@ -47,12 +57,11 @@ class EventTransaction {
this.Type = decoded.Type
this.UUID = decoded.UUID
this.ParentUUID = decoded.ParentUUID

const { metaData, error } = new MetaData().FromObject(decoded.Meta)
if (error) {
return { eventTransaction: null, error: error }
}
this.Meta = metaData
this.Meta = new MetaData(decoded.Meta.IsDir,
decoded.Meta.Sum,
decoded.Meta.Size,
decoded.Meta.CreatedAt,
decoded.Meta.Permission)

return { eventTransaction: this, error: null }
} catch (e) {
Expand Down
41 changes: 22 additions & 19 deletions eventTransaction_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const unitJS = require('unit.js')
const { v4 } = require('uuid')
const { encode, decode } = require('@msgpack/msgpack')
const { encode } = require('@msgpack/msgpack')
const { ErrArguments } = require('./errors')
const { MetaData } = require('./types')
const EventTransaction = require('./eventTransaction')
Expand Down Expand Up @@ -53,7 +53,13 @@ describe('EventTransaction Tests', () => {
Type: 'create',
UUID: uUID,
ParentUUID: parentUUID,
Meta: metaData.ToObject()
Meta: {
IsDir: metaData.IsDir,
Sum: metaData.Sum,
Size: metaData.Size,
CreatedAt: metaData.CreatedAt,
Permission: metaData.Permission
}
})

unitJS.value(error).isNull()
Expand Down Expand Up @@ -85,8 +91,7 @@ describe('EventTransaction Tests', () => {
{ encoded, error } = eventTransaction.Encode()

unitJS.value(encoded).isNull()
unitJS.value(error).isInstanceOf(Error)
unitJS.value(error.message).contains('Unrecognized object')
unitJS.value(error).is(ErrArguments)
})

it('EventTransaction .Decode()', () => {
Expand Down Expand Up @@ -138,31 +143,29 @@ describe('EventTransaction Tests', () => {
{ encoded, error } = eventTransaction.Encode(),
{ eventTransaction: decodedEventTransaction, error: error2 } = new EventTransaction().Decode(encoded)

unitJS.value(error).isNull()
unitJS.value(error).is(ErrArguments)
unitJS.value(decodedEventTransaction).isNull()
unitJS.value(error2).is(ErrArguments)
unitJS.value(error2).isInstanceOf(Error)
})

it('Should be error EventTransaction .Decode() is invalid meta data size', () => {
const uUID = v4(),
parentUUID= v4(),
metaData = new MetaData(false, 'sum', 1, 1, 'permission'),
eventTransaction = new EventTransaction('transaction1',
EventTypes.Create,
uUID,
parentUUID,
{
ToObject: () => {
return {
size: -1,
created_at: -1
}
encoded= encode({
Name: 'transaction1',
Type: EventTypes.Create,
UUID: uUID,
ParentUUID: parentUUID,
Meta: {
Size: -1,
CreatedAt: -1,
IsDir: false,
Sum: '',
Permission: ''
}
}),
{ encoded, error } = eventTransaction.Encode(),
{ eventTransaction: decodedEventTransaction, error: error2 } = new EventTransaction().Decode(encoded)

unitJS.value(error).isNull()
unitJS.value(decodedEventTransaction).isNull()
unitJS.value(error2).is(ErrArguments)
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fs-shadow-js",
"version": "1.0.4",
"version": "1.0.5",
"description": "FS-Shadow Javascript",
"main": "index.js",
"type": "commonjs",
Expand Down

0 comments on commit 1debd29

Please sign in to comment.