metarhia / globalstorage

Distributed Data Warehouse 🌍
https://metarhia.com
MIT License
60 stars 5 forks source link

Add tests for permission validation #400

Closed mille-nium closed 5 years ago

mille-nium commented 5 years ago

Closes: https://github.com/metarhia/globalstorage/issues/333

mille-nium commented 5 years ago

I'm confused about how to split this test to separate files, because it is taking almost 800 lines for now (cases only for two methods), so it gets hard to read.

\cc @belochub @nechaido @lundibundi

lundibundi commented 5 years ago

@mille-nium metatests@0.6.6 have released, if you want you can use test.resolves,test.rejects and also there is no need to write test.end() at the end of async tests. Also, before/afterEach now properly support promises.

mille-nium commented 5 years ago

@lundibundi thank you, I'll move everything to new version.

nechaido commented 5 years ago

I have a proposal for a more declarative syntax to reduce boilerplate, though it's a matter for debate if it is more readable. Example:

[
  // ... cases
  {
    name: 'no permission for category with subsystem/catalog',
    record: {
      Name: 'person2S2',
      Subsystem: subsystems.S2,
    },
    category: 'Person',
    user: users.S2.InsertOnlyUser,
    error: EXPECTED_ERROR,
  },
].forEach(({ name, record, category, user, error }) =>
  test.test(`remoteProvider.create: ${name}`, async test => {
    if (user) {
      await login(user);
    }

    const creation = remoteProvider.create(category, record);
    if (error) {
      const error = await test.rejects(creation, EXPECTED_ERROR);
      test.strictSame(error.code, EXPECTED_ERROR_CODE);
    } else {
      await test.resolves(creation);
    }
  })
);

@belochub @lundibundi @mille-nium WDYT?

mille-nium commented 5 years ago

@nechaido this idea has been mentioned already by @lundibundi, however, it seemed to me like more unreadable one, so I haven't changed it. In addition, there are cases, where tests can't be designed in this way (there is some additional preparation), so I'm not sure whether it is okay to write these tests in different ways. Though I can be mistaken.

belochub commented 5 years ago

Landed in https://github.com/metarhia/globalstorage/commit/075d4f722d3bcf95f3c9a395b5e058b16053f691.