Breeze / breeze-client

Breeze for JavaScript clients
MIT License
38 stars 16 forks source link

DataType.fromValue has false positives for guids #79

Open thcgit opened 1 year ago

thcgit commented 1 year ago

The following unit tests fails on version 2.1.5:

  test("example", () => {
    expect(DataType.fromValue("foo")).toBe(DataType.String);
    expect(DataType.fromValue("f16fb858-1e02-46fb-8467-a5fb45a7067f")).toBe(
      DataType.Guid
    );
    expect(DataType.fromValue("foo-f16fb858-1e02-46fb-8467-a5fb45a7067f")).toBe(
      DataType.String
    );
  });

The 3rd expectation fails - fromValue returns DataType.Guid, which is probably not the correct behavior.

The problem seems to be in core.ts where the isGuid function uses a regular expression without a start or end anchor:

function isGuid(value: any) {
  return (typeof value === "string") && /[a-fA-F\d]{8}-(?:[a-fA-F\d]{4}-){3}[a-fA-F\d]{12}/.test(value);
}

I tried to create a pull request to fix this but ran into a few issues:

  1. There's no package-lock.json in the root of the repo so I'm unsure if npm installed compatible package versions.
  2. The build command failed on the downlevel-dts step, possibly due to some incompatible package version.
  3. When running the unit tests, many tests fail trying to make http requests to services like http://localhost:34377/breeze/NorthwindIBModel/Metadata. Is there a script for spinning up the services required for tests, or documentation on how to set them up?
steveschmitt commented 1 year ago

Good catch! Thanks for that.

Sorry about the missing package-lock.json. The versions in package.json should have been sufficient to create a reliable build, but apparently that's not the case.

The unit tests require spinning up a server separately, using the code in the breeze.server.net repo.