-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from digital-land/feat/datasetSlugNameMap
Feat/dataset slug name map
- Loading branch information
Showing
25 changed files
with
322 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import config from '../../config/index.js' | ||
|
||
export default (service) => { | ||
const serviceName = config.serviceName | ||
|
||
return serviceName.replace('Provide', service) | ||
const getFullServiceName = (service) => { | ||
if (!service || typeof service !== 'string') { | ||
throw new Error('Service name must be a non-empty string') | ||
} | ||
return config.serviceName.replace('Provide', service) | ||
} | ||
|
||
export default getFullServiceName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import datasette from '../../services/datasette.js' | ||
|
||
export const getDatasetSlugNameMapping = async () => { | ||
const datasetSlugNameTable = await datasette.runQuery('select dataset, name from dataset') | ||
|
||
const datasetMapping = new Map() | ||
datasetSlugNameTable.rows.forEach(([slug, name]) => { | ||
datasetMapping.set(slug, name) | ||
}) | ||
return datasetMapping | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import datasette, { formatData } from '../../src/services/datasette.js' | ||
import axios from 'axios' | ||
import { vi, describe, beforeEach, afterEach, it, expect } from 'vitest' | ||
|
||
describe('datasette', () => { | ||
beforeEach(() => { | ||
vi.spyOn(axios, 'get').mockResolvedValue({ | ||
data: { | ||
columns: ['column1', 'column2'], | ||
rows: [ | ||
['value1', 'value2'], | ||
['value3', 'value4'] | ||
] | ||
} | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.mocked(axios.get).mockReset() | ||
}) | ||
|
||
it('runs a SQL query and returns the results', async () => { | ||
const query = 'SELECT * FROM table_name' | ||
const result = await datasette.runQuery(query) | ||
|
||
expect(result).toEqual({ | ||
columns: ['column1', 'column2'], | ||
formattedData: [ | ||
{ column1: 'value1', column2: 'value2' }, | ||
{ column1: 'value3', column2: 'value4' } | ||
], | ||
rows: [ | ||
['value1', 'value2'], | ||
['value3', 'value4'] | ||
] | ||
}) | ||
}) | ||
|
||
it('throws an error if the query fails', async () => { | ||
vi.spyOn(axios, 'get').mockRejectedValue(new Error('Query failed')) | ||
|
||
await expect(datasette.runQuery('SELECT * FROM table_name')).rejects.toThrowError('Query failed') | ||
}) | ||
|
||
it('formats data correctly', () => { | ||
const columns = ['column1', 'column2'] | ||
const rows = [['value1', 'value2'], ['value3', 'value4']] | ||
const formattedData = formatData(columns, rows) | ||
|
||
expect(formattedData).toEqual([ | ||
{ column1: 'value1', column2: 'value2' }, | ||
{ column1: 'value3', column2: 'value4' } | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.