Uploaded image for project: 'Moodle app'
  1. Moodle app
  2. MOBILE-4232

Avoid mock some methods in testing that involve db operations

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.0
    • Unit tests
    • Hide
      • This issue should be tested by a developer.
      1. Use a method that insert something in DB, for example: "CoreSite.setLocalSiteConfig('key', 'value')"
      2. Use a method that read the value saved in the previous step, for example: "CoreSite.getLocalSiteConfig('key')"
      3. Use a method that update the value saved in the previous step, for example: get an instance of the config table with this code:       

      const configTable = asyncInstance(() => CoreSites.getSiteTable(CONFIG_TABLE, {
      siteId,
      config: { cachingStrategy: CoreDatabaseCachingStrategy.Testing },
      primaryKeyColumns: ['name'],
      })); 

       And update the record with that:

      await configTable.update({ name: key, value: 'updatedValue' }, { name: key, value: 'previousValue' }); 

      1. Use a method that read the value updated in the previous step, for example: "CoreSite.getLocalSiteConfig('key')"
      2. Use a method that remove the value saved in the previous step, for example: "CoreSite.deleteSiteConfig('key')"
      3. Use a method that read the value saved in the previous step, for example: "CoreSite.getLocalSiteConfig('key')". It should throw an exception because cannot found the record.
      Show
      This issue should be tested by a developer. Use a method that insert something in DB, for example: "CoreSite.setLocalSiteConfig('key', 'value')" Use a method that read the value saved in the previous step, for example: "CoreSite.getLocalSiteConfig('key')" Use a method that update the value saved in the previous step, for example: get an instance of the config table with this code:        const configTable = asyncInstance(() => CoreSites.getSiteTable(CONFIG_TABLE, { siteId, config: { cachingStrategy: CoreDatabaseCachingStrategy.Testing }, primaryKeyColumns: [ 'name' ], }));  And update the record with that: await configTable.update({ name: key, value: 'updatedValue' }, { name: key, value: 'previousValue' }); Use a method that read the value updated in the previous step, for example: "CoreSite.getLocalSiteConfig('key')" Use a method that remove the value saved in the previous step, for example: "CoreSite.deleteSiteConfig('key')" Use a method that read the value saved in the previous step, for example: "CoreSite.getLocalSiteConfig('key')". It should throw an exception because cannot found the record.
    • MOODLE_401_STABLE

      When we are making unit / integration tests for any feature that involves database CRUD process we have to mock some methods. To avoid that maybe we can create a config to run tests with a "database" in memory, like a javascript object.

            alfonso.salces@moodle.com Alfonso Salces
            alfonso.salces@moodle.com Alfonso Salces
            Noel De Martin Noel De Martin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.