Skip to content

Refactor and improve commit-related tests #234

@yeraydavidrodriguez

Description

@yeraydavidrodriguez

As @josecelano suggested here, we should improve the tests in which the scenario after creating jobs and changing its status is checked inspecting the commits. In those tests, the ACT part has an abstraction level different from the ASSET part. Also, those tests does not inspect all the required conditions for the final scenario as the job status is not being checked.

An example of this kind of to-fix tests would be this one:

  it('should mark a job that is not the last created one as finished', async () => {
    const queue = await createTestQueue(commitOptionsForTests())

    await queue.createJob(dummyPayload())
    await queue.createJob(dummyPayload())
    await queue.markJobAsStarted(dummyPayload())
    const finishJobCommit = await queue.markJobAsFinished(dummyPayload())
    expect(queue.isEmpty()).toBe(false)

    // Commit was created
    const latestCommit = getLatestCommitHash(queue.getGitRepoDir())
    expect(finishJobCommit.hash.equalsTo(latestCommit)).toBe(true)
  })

An example of same-abstraction-level, more comprehensible test should be:

  it('should mark a job that is not the last created one as finished', async () => {
    // ARRANGE
    const queue = await createTestQueue(commitOptionsForTests())

    // ACT

    // Create the first job
    const firstCreatedJob = await queue.createJob(dummyPayload())

    // Create the second job
    await queue.createJob(dummyPayload())

    // Mark first job as started
    await queue.markJobAsStarted(firstCreatedJob.getJobId(), dummyPayload())

    // Mark first job as finished
    const finishJobCommit = await queue.markJobAsFinished(
      firstCreatedJob.getJobId(),
      dummyPayload()
    )

    // ASSERT

    // Commit was created
    const latestCommit = getLatestCommitHash(queue.getGitRepoDir())
    expect(finishJobCommit.hash.equalsTo(latestCommit)).toBe(true)

    // New assert
    const firstJob = queue.getJob(firstCreatedJob.getJobId())
    expect(firstJob.isFinished()).toBe(true)
  })

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions