break-pointer / homebridge-tion

Homebridge plugin to control Tion breezers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Writing auth data to persistent storage fails

bochkarev opened this issue · comments

Writing fails because parent directory does not exist.

$ npm run test
...
FAIL  test/tion_api.test.ts
  ● Console

    console.log
      Auth tokens not persisted

      at Function.MockLog (test/mocks.ts:8:45)

    console.log
      Loading system state

      at Function.MockLog (test/mocks.ts:8:45)

    console.log
      TionApi - no token

      at Function.MockLog (test/mocks.ts:8:45)

    console.log
      TionAuthApi - authenticating using password

      at Function.MockLog (test/mocks.ts:8:45)

    console.log
      TionApi - no_token: ENOENT: no such file or directory, open '/Users/bochkarev/tion/homebridge-tion/test/data/homebridge-tion.auth.json'

      at Function.MockLog (test/mocks.ts:8:45)
          at Generator.throw (<anonymous>)

  ● Test Tion API › It should login and recieve state

    ENOENT: no such file or directory, open '/Users/bochkarev/tion/homebridge-tion/test/data/homebridge-tion.auth.json'

      138 |
      139 |     public async save(authData: ITionAuthData): Promise<void> {
    > 140 |         fs.writeFileSync(this.getStatePath(), JSON.stringify(authData, null, 4), {encoding: 'utf8'});
          |            ^
      141 |         this.log.debug('Auth tokens persisted');
      142 |     }
      143 |

      at TionFilesystemAuthStorage.<anonymous> (src/tion/auth.ts:140:12)
      at src/tion/auth.ts:8:71
      at Object.<anonymous>.__awaiter (src/tion/auth.ts:4:12)
      at TionFilesystemAuthStorage.save (src/tion/auth.ts:109:16)
      at TionAuthApi.<anonymous> (src/tion/auth.ts:92:32)