Skip to content

Commit

Permalink
chore: refactor store to return the added object when addition occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Dec 30, 2024
1 parent 33cc8c0 commit 5e988fa
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions __tests__/checks/githubOrgMFA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ beforeAll(async () => {
})

beforeEach(async () => {
await resetDatabase(knex);
[project] = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
await resetDatabase(knex)
project = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
})

afterAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/checks/softwareDesignTraining.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ beforeAll(async () => {
})

beforeEach(async () => {
await resetDatabase(knex);
[project] = await addProject({ name: 'project', category: 'impact' })
await resetDatabase(knex)
project = await addProject({ name: 'project', category: 'impact' })
})

afterAll(async () => {
Expand Down
8 changes: 4 additions & 4 deletions __tests__/cli/workflows.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('run update-github-orgs', () => {

test('Should update the project with new information available', async () => {
// Prepare the database
const [project] = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
const project = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id })
const projects = await getAllProjects()
expect(projects.length).toBe(1)
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('run upsert-github-repositories', () => {
})
test('Should add the repositories related to the organization', async () => {
// Prepare the database
const [project] = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
const project = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id })
const projects = await getAllProjects()
expect(projects.length).toBe(1)
Expand All @@ -123,8 +123,8 @@ describe('run upsert-github-repositories', () => {
expect(githubRepos[0].description).toBe(sampleGithubRepository.description)
})
test('Should update the repositories related to the organization', async () => {
const [project] = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
const [org] = await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id })
const project = await addProject({ name: sampleGithubOrg.login, category: 'impact' })
const org = await addGithubOrg({ login: sampleGithubOrg.login, html_url: sampleGithubOrg.html_url, project_id: project.id })
const githubRepoData = simplifyObject(sampleGithubRepository, {
include: ['node_id', 'name', 'full_name', 'html_url', 'url', 'git_url', 'ssh_url', 'clone_url', 'visibility', 'default_branch']
})
Expand Down
2 changes: 1 addition & 1 deletion src/cli/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function runAddProjectCommand (knex, options = {}) {

answers.githubUrls = Array.isArray(answers.githubUrls) ? answers.githubUrls : stringToArray(answers.githubUrls)

const [project] = await addProject({
const project = await addProject({
name: answers.name.toLowerCase(),
category: answers.category
})
Expand Down
6 changes: 3 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const getAllFn = knex => (table) => {

const addFn = knex => (table, record) => {
debug(`Inserting ${record} in ${table}`)
return knex(table).insert(record).returning('*')
return knex(table).insert(record).returning('*').then(results => results[0])
}

const upsertRecord = async ({ knex, table, uniqueCriteria, data }) => {
Expand All @@ -34,7 +34,7 @@ const addGithubOrganization = knex => async (organization) => {
throw new Error(`Organization with login (${organization.login}) already exists`)
}
debug(`Inserting organization (${organization.login})...`)
return knex('github_organizations').insert(organization).returning('*')
return knex('github_organizations').insert(organization).returning('*').then(results => results[0])
}

const addProject = knex => async (project) => {
Expand All @@ -48,7 +48,7 @@ const addProject = knex => async (project) => {
return knex('projects').insert({
name,
category
}).returning('*')
}).returning('*').then(results => results[0])
}

const getCheckByCodeName = knex => (codeName) => {
Expand Down

0 comments on commit 5e988fa

Please sign in to comment.