Skip to content

Commit

Permalink
feat(HMS-2304): Nest list endpoints with 'data' (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer authored Aug 11, 2023
1 parent ddf305f commit de7afae
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 127 deletions.
16 changes: 12 additions & 4 deletions src/API/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const typesUrlForProvider = (provider, region) => {
};

export const fetchSourcesList = async (provider) => {
const { data } = await axios.get(provisioningUrl(`sources?provider=${provider}`));
const {
data: { data },
} = await axios.get(provisioningUrl(`sources?provider=${provider}`));
return data;
};

Expand All @@ -22,13 +24,17 @@ export const fetchSourceUploadInfo = async (sourceID) => {
};

export const fetchPubkeysList = async () => {
const { data } = await axios.get(provisioningUrl('pubkeys'));
const {
data: { data },
} = await axios.get(provisioningUrl('pubkeys'));
return data;
};

export const fetchInstanceTypesList = async (region, provider) => {
const url = typesUrlForProvider(provider, region);
const { data } = await axios.get(url);
const {
data: { data },
} = await axios.get(url);
return data;
};

Expand Down Expand Up @@ -61,6 +67,8 @@ export const fetchReservationByProvider = async (reservationID, provider) => {
};

export const fetchLaunchTemplates = async (sourceID, region) => {
const { data } = await axios.get(provisioningUrl(`sources/${sourceID}/launch_templates?region=${region}`));
const {
data: { data },
} = await axios.get(provisioningUrl(`sources/${sourceID}/launch_templates?region=${region}`));
return data;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ describe('InstanceTypesSelect', () => {
test('populate AWS instance types select', async () => {
await mountSelectAndClick();
const items = await screen.findAllByLabelText(/^Instance Type/);
expect(items).toHaveLength(awsInstanceTypeList.filter((type) => type.architecture === 'x86_64').length); // arm64 is filtered
expect(items).toHaveLength(awsInstanceTypeList.data.filter((type) => type.architecture === 'x86_64').length); // arm64 is filtered
});

test('populate Azure instance types select', async () => {
await mountSelectAndClick('azure');
const items = await screen.findAllByLabelText(/^Instance Type/);
expect(items).toHaveLength(azureInstanceTypeList.filter((type) => type.architecture === 'x86_64').length); // arm64 is filtered
expect(items).toHaveLength(azureInstanceTypeList.data.filter((type) => type.architecture === 'x86_64').length); // arm64 is filtered
});

describe('search', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Pubkeys', () => {
const { server, rest } = window.msw;
server.use(
rest.get(provisioningUrl('pubkeys'), (req, res, ctx) => {
return res(ctx.status(200), ctx.json([]));
return res(ctx.status(200), ctx.json({ data: [] }));
})
);
render(<Pubkeys setStepValidated={jest.fn()} />);
Expand All @@ -35,7 +35,7 @@ describe('Pubkeys', () => {
render(<PubkeySelect setStepValidated={jest.fn()} />, { contextValues: { provider: 'azure' } });
const select = await screen.findByText('Select public key...');
await userEvent.click(select);
await userEvent.click(screen.getByText(pubkeysList[0].name));
await userEvent.click(screen.getByText(pubkeysList.data[0].name));
expect(screen.getByText('Key format is not support', { exact: false })).toBeInTheDocument();
});

Expand Down
4 changes: 2 additions & 2 deletions src/Components/SourcesSelect/SourcesSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('SourcesSelect', () => {
await userEvent.click(selectDropdown);

const items = await screen.findAllByLabelText('Source account');
expect(items).toHaveLength(sourcesList.length);
expect(items).toHaveLength(sourcesList.data.length);
});

test('filters and preselect single available source', async () => {
Expand All @@ -30,7 +30,7 @@ describe('SourcesSelect', () => {
await userEvent.click(selectDropdown);

const items = await screen.findAllByLabelText('Source account');
expect(items).toHaveLength(sourcesList.length);
expect(items).toHaveLength(sourcesList.data.length);
});

test('gcp source verifying email', async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/Components/TemplateSelect/TemplateSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ describe('TemplateSelect', () => {
await userEvent.click(selectDropdown);

const items = await screen.findAllByLabelText('template option');
expect(items).toHaveLength(templates.length);
expect(items).toHaveLength(templates.data.length);
});
test('clear chosen template', async () => {
render(<TemplateSelect />, { provider: 'aws', contextValues: { chosenSource: '1' } });
const selectDropdown = await screen.findByText('Select templates');
await userEvent.click(selectDropdown);

await userEvent.click(await screen.findByText(templates[0].name));
await userEvent.click(await screen.findByText(templates.data[0].name));
await userEvent.click(await screen.findByLabelText('clear template selection'));
const placeholder = await screen.findByText('Select templates');
expect(placeholder).toBeInTheDocument();
Expand All @@ -30,7 +30,7 @@ describe('TemplateSelect', () => {
const chosenSource = '1';
server.use(
rest.get(provisioningUrl(`sources/${chosenSource}/launch_templates`), (req, res, ctx) => {
return res(ctx.status(200), ctx.json([]));
return res(ctx.status(200), ctx.json({ data: [] }));
})
);
render(<TemplateSelect />, { provider: 'aws', contextValues: { chosenSource: chosenSource } });
Expand Down
178 changes: 91 additions & 87 deletions src/mocks/fixtures/instanceTypes.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,96 @@
export const awsInstanceTypeList = [
{
id: 1,
name: 'm5dn.12xlarge',
vcpus: 48,
cores: 24,
memory: 196608,
supported: true,
architecture: 'x86_64',
},
{
id: 2,
name: 't4g.nano',
vcpus: 2,
cores: 2,
memory: 512,
architecture: 'arm64',
},
{
id: 3,
name: 't1.micro',
vcpus: 1,
cores: 2,
memory: 128,
supported: true,
architecture: 'x86_64',
},
{
id: 4,
name: 't1.nano',
vcpus: 1,
cores: 1,
memory: 512,
architecture: 'x86_64',
supported: false,
},
];
export const awsInstanceTypeList = {
data: [
{
id: 1,
name: 'm5dn.12xlarge',
vcpus: 48,
cores: 24,
memory: 196608,
supported: true,
architecture: 'x86_64',
},
{
id: 2,
name: 't4g.nano',
vcpus: 2,
cores: 2,
memory: 512,
architecture: 'arm64',
},
{
id: 3,
name: 't1.micro',
vcpus: 1,
cores: 2,
memory: 128,
supported: true,
architecture: 'x86_64',
},
{
id: 4,
name: 't1.nano',
vcpus: 1,
cores: 1,
memory: 512,
architecture: 'x86_64',
supported: false,
},
],
};

export const azureInstanceTypeList = [
{
name: 'Standard_A1_v2',
vcpus: 1,
cores: 1,
memory_mib: 2000,
storage_gb: 10,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
export const azureInstanceTypeList = {
data: [
{
name: 'Standard_A1_v2',
vcpus: 1,
cores: 1,
memory_mib: 2000,
storage_gb: 10,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
},
},
},
{
name: 'Standard_A2_v2',
vcpus: 2,
cores: 2,
memory_mib: 4000,
storage_gb: 20,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
{
name: 'Standard_A2_v2',
vcpus: 2,
cores: 2,
memory_mib: 4000,
storage_gb: 20,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
},
},
},
{
name: 'Standard_A2m_v2',
vcpus: 2,
cores: 2,
memory_mib: 16000,
storage_gb: 20,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
{
name: 'Standard_A2m_v2',
vcpus: 2,
cores: 2,
memory_mib: 16000,
storage_gb: 20,
supported: true,
architecture: 'x86_64',
azure: {
gen_v1: true,
gen_v2: false,
},
},
},
{
name: 'Standard_D16ps_v5',
vcpus: 16,
cores: 16,
memory_mib: 64000,
storage_gb: 0,
supported: true,
architecture: 'arm64',
azure: {
gen_v1: false,
gen_v2: true,
{
name: 'Standard_D16ps_v5',
vcpus: 16,
cores: 16,
memory_mib: 64000,
storage_gb: 0,
supported: true,
architecture: 'arm64',
azure: {
gen_v1: false,
gen_v2: true,
},
},
},
];
],
};
22 changes: 12 additions & 10 deletions src/mocks/fixtures/pubkeys.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
export const pubkeysList = [
{
id: 1,
name: 'lzap-ed25519-2021',
body: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap',
fingerprint: 'SHA256:gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk',
type: 'ssh-ed25519',
},
{ id: 2, name: 'pk2' },
];
export const pubkeysList = {
data: [
{
id: 1,
name: 'lzap-ed25519-2021',
body: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhnn80ZywmjeBFFOGm+cm+5HUwm62qTVnjKlOdYFLHN lzap',
fingerprint: 'SHA256:gL/y6MvNmJ8jDXtsL/oMmK8jUuIefN39BBuvYw/Rndk',
type: 'ssh-ed25519',
},
{ id: 2, name: 'pk2' },
],
};
30 changes: 17 additions & 13 deletions src/mocks/fixtures/sources.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
export const sourcesList = [
{
name: 'Source 1',
id: '1',
},
{ name: 'Source 2', id: '2' },
];
export const sourcesList = {
data: [
{
name: 'Source 1',
id: '1',
},
{ name: 'Source 2', id: '2' },
],
};

export const gcpSourcesList = [
{
name: 'GCP Source 1',
id: '10',
},
];
export const gcpSourcesList = {
data: [
{
name: 'GCP Source 1',
id: '10',
},
],
};

export const gcpSourceUploadInfo = () => ({ gcp: {} });

Expand Down
10 changes: 6 additions & 4 deletions src/mocks/fixtures/templates.fixtures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const templates = [
{ id: '1', name: 'template-1' },
{ id: '2', name: 'template-2' },
];
export const templates = {
data: [
{ id: '1', name: 'template-1' },
{ id: '2', name: 'template-2' },
],
};

0 comments on commit de7afae

Please sign in to comment.