Skip to content

Commit

Permalink
feat: [#38] Add id property to jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
yeraydavidrodriguez committed Apr 27, 2022
1 parent d47bd36 commit c4511ef
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 58 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/commit-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CommitSubjectParser} from '../../src/commit-subject-parser'
import {dummyCommitBodyText} from '../../src/__tests__/helpers'

function dummyCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

describe('CommitMessage', () => {
Expand Down
18 changes: 10 additions & 8 deletions __tests__/unit/commit-subject-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {CommitSubjectParser} from '../../src/commit-subject-parser'
describe('CommitSubjectParser', () => {
it('should parse the message key from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getMessageKey().toString()).toBe('🈺')
Expand All @@ -13,7 +13,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the message key is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
return parser.getMessageKey().toString()
}
Expand All @@ -23,7 +23,7 @@ describe('CommitSubjectParser', () => {

it('should parse the queue name from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getQueueName().toString()).toBe('queue-name')
Expand All @@ -32,7 +32,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the queue name is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝🈺: : job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: : job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
return parser.getQueueName().toString()
}
Expand All @@ -42,7 +42,7 @@ describe('CommitSubjectParser', () => {

it('should parse the job reference (commit hash) from a commit subject', () => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)

expect(parser.getJobRef().toString()).toBe(
Expand All @@ -60,7 +60,7 @@ describe('CommitSubjectParser', () => {
it('should fail when the job reference prefix exists but the reference value is invalid in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.ref.f1a69d48a01cc---af762e4ba685de7'
'📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc---af762e4ba685de7'
)
return parser.getJobRef().toString()
}
Expand All @@ -70,15 +70,17 @@ describe('CommitSubjectParser', () => {

it('should fail when the job reference prefix exists but the reference value is missing in a commit subject', () => {
const fn = (): string => {
const parser = new CommitSubjectParser('📝🈺: queue-name: job.ref.')
const parser = new CommitSubjectParser(
'📝🈺: queue-name: job.id.1 job.ref.'
)
return parser.getJobRef().toString()
}

expect(fn).toThrowError()
})

it('should return a Null Commit when the job reference does not exist', () => {
const parser = new CommitSubjectParser('📝🈺: queue-name: NAME')
const parser = new CommitSubjectParser('📝🈺: queue-name: NAME job.id.1 ')
const jobRef = parser.getJobRef()

expect(jobRef).toBeInstanceOf(CommitHash)
Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/commit-subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {CommitSubjectParser} from '../../src/commit-subject-parser'
import {QueueName} from '../../src/queue-name'

function dummyCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummyCommitSubjectText2(): string {
return '📝🈺: queue-name: job.ref.69062fe1104d187277aaec72ea56e8d993daca33'
return '📝🈺: queue-name: job.id.1 job.ref.69062fe1104d187277aaec72ea56e8d993daca33'
}

describe('CommitSubject', () => {
Expand All @@ -25,7 +25,7 @@ describe('CommitSubject', () => {
expect(commit.belongsToQueue(new QueueName('queue-name-two'))).toBe(false)

const commit2 = CommitSubjectParser.parseText(
'📝🈺: library aaa update: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
'📝🈺: library aaa update: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
)
expect(commit2.belongsToQueue(new QueueName('library aaa update'))).toBe(
true
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/committed-message-log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CommittedMessageLog} from '../../src/committed-message-log'
import {DefaultLogFields} from 'simple-git'

function dummyNewJobCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummySimpleGitCommit(
Expand Down
6 changes: 3 additions & 3 deletions __tests__/unit/committed-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {DefaultLogFields} from 'simple-git'
import {dummyCommitBodyText} from '../../src/__tests__/helpers'

function dummyNewJobCommitSubjectText(): string {
return '📝🈺: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝🈺: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

function dummyJobFinishedCommitSubjectText(): string {
return '📝✅: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
return '📝✅: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7'
}

describe('Queue', () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Queue', () => {
hash: 'f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
date: 'not relevant',
message:
'📝INVALID: queue-name: job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
'📝INVALID: queue-name: job.id.1 job.ref.f1a69d48a01cc130a64aeac5eaf762e4ba685de7',
refs: 'not relevant',
body: 'not relevant',
author_name: 'not relevant',
Expand Down
29 changes: 22 additions & 7 deletions __tests__/unit/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,37 @@ describe('Job', () => {
it('should contain a payload', () => {
const job = new Job(
'payload',
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf')
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf'),
1
)

expect(job.getPayload()).toBe('payload')
})

it('should contain a commit has where the job was created', () => {
it('should contain a commit hash where the job was created', () => {
const commitHash = new CommitHash(
'a362802b98c78df052a78796a1a7cde60a5c1faf'
)
const job = new Job('payload', commitHash)
const job = new Job('payload', commitHash, 1)

expect(job.getCommitHash()).toBe(commitHash)
})

it('should contain a Job Id', () => {
const job = new Job(
'payload',
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf'),
42
)

expect(job.getId()).toBe(42)
})

it('should be nullable', () => {
const job = new Job(
'payload',
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf')
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf'),
0
)

expect(job.getPayload()).toBe('payload')
Expand All @@ -35,17 +47,20 @@ describe('Job', () => {
it('should compare two jobs', () => {
const job1 = new Job(
'payload',
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf')
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf'),
0
)

const job2 = new Job(
'payload',
new CommitHash('8f51fa0a019b277103acc5ef75c52dfb2a9bcce3')
new CommitHash('8f51fa0a019b277103acc5ef75c52dfb2a9bcce3'),
0
)

const job3 = new Job(
'payload3',
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf')
new CommitHash('a362802b98c78df052a78796a1a7cde60a5c1faf'),
0
)

expect(job1.equalsTo(job1)).toBe(true)
Expand Down
17 changes: 11 additions & 6 deletions __tests__/unit/queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Job, NO_JOB_ID} from '../../src/job'
import {
createInitializedGitRepo,
createInitializedTempGnuPGHomeDir,
Expand All @@ -7,12 +8,10 @@ import {
getSecondToLatestCommitHash,
gitLogForLatestCommit
} from '../../src/__tests__/helpers'

import {CommitAuthor} from '../../src/commit-author'
import {CommitInfo} from '../../src/commit-info'
import {CommitOptions} from '../../src/commit-options'
import {GitRepo} from '../../src/git-repo'
import {Job} from '../../src/job'
import {Queue} from '../../src/queue'
import {QueueName} from '../../src/queue-name'
import {SigningKeyId} from '../../src/signing-key-id'
Expand Down Expand Up @@ -92,7 +91,7 @@ describe('Queue', () => {
const job = await queue.createJob(dummyPayload())

const commitHash = getLatestCommitHash(queue.getGitRepoDir())
expect(job.equalsTo(new Job(dummyPayload(), commitHash))).toBe(true)
expect(job.equalsTo(new Job(dummyPayload(), commitHash, 0))).toBe(true)
})

it('should fail when trying to create a job if the previous job has not finished yet', async () => {
Expand Down Expand Up @@ -275,7 +274,9 @@ describe('Queue', () => {
const nextJob = queue.getNextJob()

const latestCommit = getLatestCommitHash(queue.getGitRepoDir())
expect(nextJob.equalsTo(new Job(dummyPayload(), latestCommit))).toBe(true)
expect(
nextJob.equalsTo(new Job(dummyPayload(), latestCommit, NO_JOB_ID))
).toBe(true)
})
})

Expand All @@ -298,9 +299,13 @@ describe('Queue', () => {
const nextJob2 = queue2.getNextJob()

const newJob1Commit = getSecondToLatestCommitHash(queue1.getGitRepoDir())
expect(nextJob1.equalsTo(new Job(payload1, newJob1Commit))).toBe(true)
expect(nextJob1.equalsTo(new Job(payload1, newJob1Commit, NO_JOB_ID))).toBe(
true
)

const latestCommit = getLatestCommitHash(queue2.getGitRepoDir())
expect(nextJob2.equalsTo(new Job(payload2, latestCommit))).toBe(true)
expect(nextJob2.equalsTo(new Job(payload2, latestCommit, NO_JOB_ID))).toBe(
true
)
})
})
Loading

0 comments on commit c4511ef

Please sign in to comment.